phpQuestioner Posted November 10, 2007 Share Posted November 10, 2007 I am trying to check my array with a if else condition, but it does not seem to be working; what do I need to do too make this work - would I explode "asm"? <?php $asm = array("1","2","3","4","5"); if ($cat != "$asm") { echo "Not An Option"; } ?> The above code will echo out "Not An Option" even if $cat is equal to 1, 2, 3, 4, or 5. Link to comment https://forums.phpfreaks.com/topic/76717-solved-having-trouble-validating-array/ Share on other sites More sharing options...
pocobueno1388 Posted November 10, 2007 Share Posted November 10, 2007 You need to use the in_array() function. <?php $asm = array("1","2","3","4","5"); if (!in_array($cat, $asm)) { echo "Not An Option"; } ?> Link to comment https://forums.phpfreaks.com/topic/76717-solved-having-trouble-validating-array/#findComment-388390 Share on other sites More sharing options...
phpQuestioner Posted November 10, 2007 Author Share Posted November 10, 2007 thanks pocobueno1388 - i was just reading about that in the manual. Link to comment https://forums.phpfreaks.com/topic/76717-solved-having-trouble-validating-array/#findComment-388395 Share on other sites More sharing options...
pocobueno1388 Posted November 10, 2007 Share Posted November 10, 2007 No problem. Don't forget to press "Topic Solved". Link to comment https://forums.phpfreaks.com/topic/76717-solved-having-trouble-validating-array/#findComment-388396 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.