johnsmith153 Posted February 5, 2011 Share Posted February 5, 2011 if(in_array("b", $array)) { } The above checks to see if a value is present in an array, but how do I then retrieve the array key value from the matching value? $array[0] = "a"; $array[1] = "b"; $array[2] = "c"; So in the example, the answer is 1 (array key 1). Link to comment https://forums.phpfreaks.com/topic/226819-ultra-simple-array-question/ Share on other sites More sharing options...
sunfighter Posted February 5, 2011 Share Posted February 5, 2011 It's doing what you want - it's telling that b is in the array. Use array_search() to find out where. http://www.php.net/manual/en/function.array-search.php Link to comment https://forums.phpfreaks.com/topic/226819-ultra-simple-array-question/#findComment-1170378 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.