我有一个多维数组
Array
(
[0] => Array
(
[ID] => 53
[Lft] => 11
[Rght] => 24
[Title] => cafeteria
[Description] => Cafeteria
)
[1] => Array
(
[ID] => 55
[Lft] => 20
[Rght] => 21
[Title] => sanitary
[Description] => Sanitary
)
[2] => Array
(
[ID] => 58
[Lft] => 22
[Rght] => 23
[Title] => medic
[Description] => Medic
)
)
如何轻松获取所有id的数组,而不必遍历每种传统方式?
答案 0 :(得分:2)
我们可以使用array_column
基于key
从多维数组中提取一维数组。
$roles = array_column($roles, 'ID');
返回
Array (
[0] => 53
[1] => 55
[2] => 58
)