gpt4 book ai didi

php - 如何在php中获取多维数组中的所有键

转载 作者:可可西里 更新时间:2023-11-01 12:27:11 25 4
gpt4 key购买 nike

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”的所有键值?

谢谢!

最佳答案

试试这个

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 - 如何在php中获取多维数组中的所有键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11234852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com