crackpanda Posted May 29, 2009 Share Posted May 29, 2009 Hello. So what i need to do is check if an array contains a specific value, how can this be done? ??? For example, im looking for "Brick Wall" in the array $walls[]. Link to comment https://forums.phpfreaks.com/topic/160150-need-help-working-with-array-values/ Share on other sites More sharing options...
jonsjava Posted May 29, 2009 Share Posted May 29, 2009 if (in_array("Brick Wall",$walls)){ //do something } Link to comment https://forums.phpfreaks.com/topic/160150-need-help-working-with-array-values/#findComment-844948 Share on other sites More sharing options...
gevans Posted May 29, 2009 Share Posted May 29, 2009 <?php $walls = array('stone wall', 'brick wall', 'paper wall'); if(in_array('brick wall', $walls)) { //it's there } else { //it's not } ?> edit - same as jonsjava, just a little more to play with Link to comment https://forums.phpfreaks.com/topic/160150-need-help-working-with-array-values/#findComment-844953 Share on other sites More sharing options...
crackpanda Posted May 29, 2009 Author Share Posted May 29, 2009 The in_array() function works perfectly, thank you very much! Link to comment https://forums.phpfreaks.com/topic/160150-need-help-working-with-array-values/#findComment-844956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.