Cyto Posted March 10, 2012 Share Posted March 10, 2012 I would like to check multiple rows from array with elseif. It's working if i add it manually, but i would like it to check all of the rows in a single elseif. Code(First if is nothing, just a example). Row is a array filled with numbers like: 3-3, 2-2 etc. if("2-2" == $row["0"]){ echo BLUE; }elseif($dnumber == $row["0"]){ echo RED; }else{ echo WHITE; } Link to comment https://forums.phpfreaks.com/topic/258646-elseif-check-from-array/ Share on other sites More sharing options...
dragon_sa Posted March 10, 2012 Share Posted March 10, 2012 foreach ($row as $item) { if($item == "2-2"){ echo "BLUE<br/>\n"; } elseif ($item == $dnumber){ echo "RED<br/>\n"; }else{ echo "WHITE<br/>\n"; } } Link to comment https://forums.phpfreaks.com/topic/258646-elseif-check-from-array/#findComment-1325844 Share on other sites More sharing options...
Pikachu2000 Posted March 10, 2012 Share Posted March 10, 2012 Can you clarify that a bit? What is your end goal with this? Link to comment https://forums.phpfreaks.com/topic/258646-elseif-check-from-array/#findComment-1325845 Share on other sites More sharing options...
Mahngiel Posted March 10, 2012 Share Posted March 10, 2012 Shouldn't you use the $key, since the value he's trying to compare is the key for the value? foreach ($row as $item=>$key) { if($key == "2-2"){ echo "BLUE<br/>\n"; } elseif ($key == $dnumber){ echo "RED<br/>\n"; }else{ echo "WHITE<br/>\n"; } } Link to comment https://forums.phpfreaks.com/topic/258646-elseif-check-from-array/#findComment-1325867 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.