note 73992 added to function.array-keys
| From: | creator at mindcreations dot com | Date: | Tue, 20 Mar 2007 10:12:46 +0000 |
| Subject: | note 73992 added to function.array-keys | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124616@lists.php.net to get a copy of this message | ||
# This function will extract keys from a multidimensional array
function multiarray_keys($ar) {
foreach($ar as $k => $v) {
$keys[] = $k;
if (is_array($ar[$k]))
$keys = array_merge($keys, multiarray_keys($ar[$k]));
}
return $keys;
}
# Example code:
$array = array("color" => array("1stcolor" => "blue",
"2ndcolor" => "red", "3rdcolor" => "green"),
"size" => array("small", "medium",
"large"));
echo "<pre>";
print_r($array);
echo "</pre>";
echo "<pre>";
print_r(multiarray_keys($array));
echo "</pre>";
# Example output:
Array
(
[color] => Array
(
[1stcolor] => blue
[2ndcolor] => red
[3rdcolor] => green
)
[size] => Array
(
[0] => small
[1] => medium
[2] => large
)
)
Array
(
[0] => color
[1] => 1stcolor
[2] => 2ndcolor
[3] => 3rdcolor
[4] => size
[5] => 0
[6] => 1
[7] => 2
)
----
Server IP: 213.92.11.19
Probable Submitter: 217.72.97.197
----
Manual Page -- http://www.php.net/manual/en/function.array-keys.php
Edit -- https://master.php.net/note/edit/73992
Del: integrated -- https://master.php.net/note/delete/73992/integrated
Del: useless -- https://master.php.net/note/delete/73992/useless
Del: bad code -- https://master.php.net/note/delete/73992/bad+code
Del: spam -- https://master.php.net/note/delete/73992/spam
Del: non-english -- https://master.php.net/note/delete/73992/non-english
Del: in docs -- https://master.php.net/note/delete/73992/in+docs
Del: other reasons-- https://master.php.net/note/delete/73992
Reject -- https://master.php.net/note/reject/73992
Search -- https://master.php.net/manage/user-notes.php