note 11498 modified in array_keys by ronabop
| From: | ronabop@php.net | Date: | Sun, 25 Feb 2001 01:45:45 +0000 |
| Subject: | note 11498 modified in array_keys by ronabop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11555@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:
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
}
}
}
$array = array(7, 'w', 3, array(6, 5, array('x', 'y'), 1), array(11,
'z'), 10);
recurse($array, 1);
http://www.php.net/manual/array-keys.php