johnsmith153 Posted May 23, 2012 Share Posted May 23, 2012 Best way to do array_search on multi-dimensional array? $array['key1']['key2']['key3'] = "hello"; So, somehow, I provide "hello" and it returns array('key1', 'key2', 'key3'); - that would be ideal. Quote Link to comment https://forums.phpfreaks.com/topic/262993-best-way-to-do-array_search-on-multi-dimensional-array/ Share on other sites More sharing options...
Kays Posted May 23, 2012 Share Posted May 23, 2012 Have another array: <?php // create this one at the same time you created the one above. $array2['hello'] = array( array('key1', 'key2', 'key3'), ...); // assuming there can be more than one path? Quote Link to comment https://forums.phpfreaks.com/topic/262993-best-way-to-do-array_search-on-multi-dimensional-array/#findComment-1347952 Share on other sites More sharing options...
johnsmith153 Posted May 23, 2012 Author Share Posted May 23, 2012 Thanks, but I don't have access to it that way. It's stored / created in a file on another server. Strange I suppose. array_search would be perfect if it grabbed everything. Is there not a way to do this? Thanks anyway. Quote Link to comment https://forums.phpfreaks.com/topic/262993-best-way-to-do-array_search-on-multi-dimensional-array/#findComment-1347954 Share on other sites More sharing options...
Kays Posted May 23, 2012 Share Posted May 23, 2012 So? You can still loop through and organize it in the way I posted. This depends on how often you will have to check for values. If more than once, then yes, organize it. If just once (and only once), then you can loop and find it manually instead of storing it. Quote Link to comment https://forums.phpfreaks.com/topic/262993-best-way-to-do-array_search-on-multi-dimensional-array/#findComment-1347968 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.