purencool Posted August 13, 2009 Share Posted August 13, 2009 I have a multidimensional array that I don't know the contents of. How do I do a search to find how many arrays and what are their names? an example this is the print_r of the are I want to be able to automate the search of our partners. # Array ( [0] => About_Us.php # [1] => Contact_Us.php # [2] => Energy_Management.php # [3] => Environment.php # [4] => Home.php # [Our_Partners] => Array ( [0] => Ecobulb.php # [1] => Globpros.php # [2] => Powersave.php # [3] => Utiligy.php # ) [Our_Services] => Array ( [0] => 5_Step_Process.php # [1] => Electricity.php # [2] => Gas_and_Water.php # [3] => Light.php ) ) Link to comment https://forums.phpfreaks.com/topic/170040-finding-multidimensional-arrays/ Share on other sites More sharing options...
oni-kun Posted August 13, 2009 Share Posted August 13, 2009 I believe you can just use the 'each()' command, such as this: reset($array); while (list($key, $val) = each($array)) { echo "$key => $val\n"; //Write search code here } And it should list everything in the array even if unknown, then you can write a search function inside.. Link to comment https://forums.phpfreaks.com/topic/170040-finding-multidimensional-arrays/#findComment-897022 Share on other sites More sharing options...
Daniel0 Posted August 13, 2009 Share Posted August 13, 2009 Something like this? function in_array_recursive($item, array $array) { foreach ($array as $element) { if (is_array($element) && in_array_recursive($item, $element)) { return true; } else if ($element == $item) { return true; } } return false; } Link to comment https://forums.phpfreaks.com/topic/170040-finding-multidimensional-arrays/#findComment-897030 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.