note 11498 added to array_keys
| From: | kerry at lothrop dot de | Date: | Thu, 22 Feb 2001 16:50:40 +0000 |
| Subject: | note 11498 added to array_keys | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11418@lists.php.net to get a copy of this message | ||
This is the function to use if you want to recurse over an array of arrays:
$array = array(7, 'w', 3, array(6, 5, array('x', 'y'), 1), array(11,
'z'), 10);
recurse($array, 1);
function recurse ($l_array, $l_level) {
$l_keys = array_keys($l_array);
foreach ($l_keys as $l_key) {
if (is_array($l_array[$l_key])) {
recurse($l_struct[$l_key], $l_level + 1);
}
else {
# do something with $l_array[$l_key], knowing $l_level
}
}
}
http://www.php.net/manual/en/function.array-keys.php