如何在php中获取多维数组中的所有键 [英] How to get all the key in multi-dimensional array in php
本文介绍了如何在php中获取多维数组中的所有键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Array
(
[0] => Array
(
[name] => A
[id] => 1
[phone] => 416-23-55
[Base] => Array
(
[city] => toronto
)
[EBase] => Array
(
[city] => North York
)
[Qty] => 1
)
(
[1] => Array
(
[name] => A
[id] => 1
[phone] => 416-53-66
[Base] => Array
(
[city] => qing
)
[EBase] => Array
(
[city] => chong
)
[Qty] => 2
)
)
如何获取格式为0, name, id, phone, Base, city, Ebase, Qty"的所有键值?
How can I get the all the key value with the format "0, name, id, phone, Base, city, Ebase, Qty"?
谢谢!
推荐答案
试试这个
function array_keys_multi(array $array)
{
$keys = array();
foreach ($array as $key => $value) {
$keys[] = $key;
if (is_array($value)) {
$keys = array_merge($keys, array_keys_multi($value));
}
}
return $keys;
}
这篇关于如何在php中获取多维数组中的所有键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文