Your code:
foreach($getters as $key => $value)
switch ($key) {
case 'Year' && 'Year1':
if("$Year1" ==""){
array_push($queries, "(bk.year = '$Year')");
} else {
array_push($queries, "(bk.year BETWEEN '$Year' AND '$Year1')");
}
break;
}
}
shows two issues:
-
case
statements don't work this way. You can't use boolean operators the same way here like when using anif()
statement. (see manual) - You cannot expect the iterator variable
$key
inforeach($getters as $key=>$value)
hold both values at the same time, which you imply by saying'Year' && 'Year1'
!
To solve those issues, you could do something like:
foreach($getters as $key => $value)
switch ($key) {
case 'Year':
if($getters["Year1"] ==""){
array_push($queries, "(bk.year = '{$value}')");
} else {
array_push($queries, "(bk.year BETWEEN '{$value}' AND '{$getters['Year1']}')");
}
break;
}
}
In this case the block is executed when the foreach($getters)
hits the key 'Year'
. The if
statement now handles 'Year1'
correctly by accessing the value in the array directly instead of looking at the iterator variables.