如何从此嵌套数组中获取键 151,152 并将它们存储为单独的数组
Array
(
[151] => Array
(
[152] => Array
(
)
)
)
function recursive_keys($input){
$output = array_keys($input);
foreach($input as $val){
if (is_array($val)){
$output = array_merge($output, recursive_keys($val));
}
}
return $output;
}
递归扩展它可以处理的数组的深度。
$newArray = array();
foreach($array as $key => $val){
$newArray[] = $key;
foreach($val as $key2 => $val2){
$newArray[] = $key2;
}
}