Optimizing PHP code (trying to determine min/max/between case)

Posted by Swizzh on Stack Overflow See other posts from Stack Overflow or by Swizzh
Published on 2011-01-07T15:32:28Z Indexed on 2011/01/07 15:54 UTC
Read the original article Hit count: 160

I know this code-bit does not conform very much to best coding practices, and was looking to improve it, any ideas?

if ($query['date_min'] != _get_date_today())
    $mode_min = true;
if ($query['date_max'] != _get_date_today())
    $mode_max = true;

if ($mode_max && $mode_min)
    $mode = "between";
elseif ($mode_max && !$mode_min)
    $mode = "max";
elseif (!$mode_max && $mode_min)
    $mode = "min";
else
    return;

if ($mode == "min" || $mode == "between") {
    $command_min = "A";
}
if ($mode == "max" || $mode == "between") {
    $command_max = "B";
}
if ($mode == "between") {
    $command = $command_min . " AND " . $command_max;
} else {
    if ($mode == "min")
        $command = $command_min;
    if ($mode == "max")
        $command = $command_max;
}

echo $command;

© Stack Overflow or respective owner

Related posts about php

Related posts about optimization