Get all the keys from a hierarchical hash
| From: | Scott Baker | Date: | Thu, 23 Jun 2011 21:17:30 +0000 |
| Subject: | Get all the keys from a hierarchical hash | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-313687@lists.php.net to get a copy of this message | ||
I have a multi-tier hash (see below) and I'd like to be "search" the
hash for a given $id, and return that section, regardless of how many
layers deep it is. Sort of like how xpath works?
Once I have that I'd like get ALL the children of a given node. So I
could ask for 86, and get 36, 38, 56, etc and all THEIR children.
Basically I want *all* the ID #s that are children.
Array
(
[88] => Array
(
[109] =>
)
[86] => Array
(
[36] => Array
(
[8] =>
[121] =>
[127] =>
[135] =>
[144] =>
[161] =>
[165] =>
)
[38] => Array
(
[18] =>
[39] =>
[156] =>
[158] =>
[182] =>
)
[56] =>
[97] =>
[107] => Array
(
[240] =>
)
[115] =>
[123] =>
[146] =>
[149] =>
[223] =>
)
[157] => Array
(
[3] => Array
(
[5] => Array
(
[11] =>
)
[13] => Array
(
[6] =>
[7] =>
[98] => Array
(
[81] =>
)
)
[111] => Array
(
[10] =>
[17] =>
[110] =>
)
)
[148] => Array
(
[9] =>
[87] =>
[102] =>
[104] =>
[114] =>
[130] =>
[133] =>
[160] =>
[201] =>
[237] =>
[238] =>
)
)
)