Having this code:
$main = !empty($searchResults['main']) ? $searchResults['main'] : null;
$second = !empty($searchResults['second']) ? $searchResults['second'] : null;
$third = !empty($searchResults['third']) ? $searchResults['third'] : null;
#if(($main) || ($second) || ($third))
if((($main) || ($second) || ($third)) !== NULL)
{
foreach ((array)$searchResults as $key => $value)
{
switch ($key)
{
case "main":
....
What can it be done to fix/improve this code?
By fix I mean that I need a way to avoid running switch on empty keys
foreach ($searchResults as $key => $value)
{
if(empty($value)) continue;
...
I would personally just do
if(!empty($searchResults['main'])
{
$main = $searchResults['main'];
//do stuff
}
if(!empty($searchResults['second'])
{
$second = $searchResults['second'];
//do stuff
}
..etc.