SCook Posted October 30, 2008 Share Posted October 30, 2008 Hi gang, Quick question here: I want to retrieve a specific value in a multi-dimensional array. array_search does not seem to work. The array will have two keys for each index val1 and val2 After sorting the array, I want to retrieve the poistion in the array of val1 based on a specific value. Any help? Thanks. Link to comment https://forums.phpfreaks.com/topic/130731-retrieving-the-index-of-a-value-in-a-multi-dimensional-array/ Share on other sites More sharing options...
bobbinsbro Posted October 30, 2008 Share Posted October 30, 2008 you could probably make something work using array_filter and a callback function, but i'm no good there. i would do it the dumb (= easy ) way: $searchElem = "the element you are looking for"; $location = 0; $dim1Count = count($array); for($i = 0; $i < $dim1Count; ++$i){ foreach($array[$i] as $bla){ if ($bla == $searchElem){ //or strcmp() for strings or something break; } } $location = $i; break; } Link to comment https://forums.phpfreaks.com/topic/130731-retrieving-the-index-of-a-value-in-a-multi-dimensional-array/#findComment-678447 Share on other sites More sharing options...
SCook Posted October 30, 2008 Author Share Posted October 30, 2008 I can do it looping through the array, I was just wondering iif there was a built in function to do that task Link to comment https://forums.phpfreaks.com/topic/130731-retrieving-the-index-of-a-value-in-a-multi-dimensional-array/#findComment-678455 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.