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 ) ) Quote Link to comment 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.. Quote Link to comment 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; } Quote Link to comment 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.