我有了2个阵列像这张图片上的集合:如何获得一个数组内数组的数组键
所以有:
array 63 has two keys 70 and 72
array 64 has key 71
我想要什么要做的是拿到钥匙70,72,71。
如何得到那些钥匙?
我有了2个阵列像这张图片上的集合:如何获得一个数组内数组的数组键
所以有:
array 63 has two keys 70 and 72
array 64 has key 71
我想要什么要做的是拿到钥匙70,72,71。
如何得到那些钥匙?
$keys = $collection->flatMap(function ($item) {
return array_keys($item);
});
如果你觉得有可能是重复的,钉在通话过程中unique
末:
$keys = $collection->flatMap(function ($item) {
return array_keys($item);
})->unique();
这就是我所说的“灌篮与扣篮” – lewis4u
试试这个:
$keys = [];
$collection->each(function ($item) use (&$keys) {
$keys = array_merge($keys, array_keys($item));
});
你有没有尝试过使用嵌套的foreach? – EddyTheDove
不......你能指点我一个方向吗 – lewis4u
对不起,我的意思是嵌套的foreach – EddyTheDove