<?php
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;
}
?>
示例代码:
<?php
$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
)