AV1611 Posted December 27, 2006 Share Posted December 27, 2006 $array contains apple, orange, bananaI want to do:if ($string == of the items in $array[])what is the syntax?Thanks Link to comment https://forums.phpfreaks.com/topic/31981-solved-if-clause-against-an-array/ Share on other sites More sharing options...
batman99 Posted December 27, 2006 Share Posted December 27, 2006 Try something like this[code]foreach($array as $value) { if ($string==$value) { do something }}[/code] Link to comment https://forums.phpfreaks.com/topic/31981-solved-if-clause-against-an-array/#findComment-148421 Share on other sites More sharing options...
Barand Posted December 27, 2006 Share Posted December 27, 2006 if (in_array($str, $array)) { // do it} Link to comment https://forums.phpfreaks.com/topic/31981-solved-if-clause-against-an-array/#findComment-148423 Share on other sites More sharing options...
AV1611 Posted December 27, 2006 Author Share Posted December 27, 2006 Thanks Link to comment https://forums.phpfreaks.com/topic/31981-solved-if-clause-against-an-array/#findComment-148427 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.