Link to home
Start Free TrialLog in
Avatar of radarhill
radarhill

asked on

Determining how 'deep' an element of a multidimensional array is

I need to determine how 'deep' an element is within a multidimensional array. For example, following the code snippet, how can I determine whether an element is in the first level, the second level, the third level, etc.? How can I determine that "Vancouver" is nested three levels deep?

Ideally I would be looking for a return of an integer - so looking for "Countries" would return 0, "USA" would return 1, "Seattle" would return 2, etc.
$myArray = array(
		"Countries" => array(
				"Canada" => array(
						"Vancouver", "Toronto"),
				"USA" => array(
						"New York", "Seattle"),
				     ),
		);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of radarhill
radarhill

ASKER

Perfect - thanks!