brooksh Posted March 24, 2012 Share Posted March 24, 2012 I'm sure this is possible, but I'm not having any luck. $array = array("11:23", "12:46", "13:34", "14:34", "14:85"); if (in_array('12', $array)) { echo "yes"; } else { echo "no"; }} Link to comment https://forums.phpfreaks.com/topic/259656-find-term-within-an-array/ Share on other sites More sharing options...
Dathremar Posted March 24, 2012 Share Posted March 24, 2012 I don't understand whats the question here. What do You need help with? Link to comment https://forums.phpfreaks.com/topic/259656-find-term-within-an-array/#findComment-1330817 Share on other sites More sharing options...
brooksh Posted March 24, 2012 Author Share Posted March 24, 2012 If the number 12 is found within the array, I want it to echo yes. Link to comment https://forums.phpfreaks.com/topic/259656-find-term-within-an-array/#findComment-1330819 Share on other sites More sharing options...
Dathremar Posted March 24, 2012 Share Posted March 24, 2012 What You have is correct. If there is 12 in the array it will print yes. Link to comment https://forums.phpfreaks.com/topic/259656-find-term-within-an-array/#findComment-1330821 Share on other sites More sharing options...
Zane Posted March 24, 2012 Share Posted March 24, 2012 I'm sure there's a more efficient way using an array_map, but this is the best I can come up with off the top of my head. $array = array("11:23", "12:46", "13:34", "14:34", "14:85"); foreach($array as $value) { if(strpos($value, "12") !== FALSE) { echo "Yes"; } } Link to comment https://forums.phpfreaks.com/topic/259656-find-term-within-an-array/#findComment-1330822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.