PHP7中文手册2018 带注释 最新chm版
1、第一反应foreach,效率比较低
2、推荐使用array_column
$name_list = array_column($arr, 'id');
如下示例:
$arr = Array
(
[0] => Array
(
[id] => 2188573
[notes] =>
[color] =>
[active] => 1
[option_reqs] => 0
[option_priority] => 0
[option_automation] => 0
[options] => O:8:"stdClass":4:{s:19:"requirementsEnabled";i:1;s:19:"testPriorityEnabled";i:1;s:17:"automationEnabled";i:1;s:16:"inventoryEnabled";i:0;}
[prefix] => 00023
)
[1] => Array
(
[id] => 2188572
[notes] => 互联网金融核心SIT3测试
[color] =>
[active] => 1
[option_reqs] => 0
[option_priority] => 0
[option_automation] => 0
[options] => O:8:"stdClass":4:{s:19:"requirementsEnabled";i:1;s:19:"testPriorityEnabled";i:1;s:17:"automationEnabled";i:1;s:16:"inventoryEnabled";i:0;}
[prefix] => 00022
)
[2] => Array
(
[id] => 2149077
[notes] =>
[color] =>
[active] => 1
[option_reqs] => 0
[option_priority] => 0
[option_automation] => 0
[options] => O:8:"stdClass":4:{s:19:"requirementsEnabled";i:1;s:19:"testPriorityEnabled";i:1;s:17:"automationEnabled";i:1;s:16:"inventoryEnabled";i:0;}
[prefix] => 00021
)
[3] => Array
(
[id] => 1986569
[notes] =>
[color] =>
[active] => 1
[option_reqs] => 0
[option_priority] => 0
[option_automation] => 0
[options] => O:8:"stdClass":4:{s:19:"requirementsEnabled";i:1;s:19:"testPriorityEnabled";i:1;s:17:"automationEnabled";i:1;s:16:"inventoryEnabled";i:0;}
[prefix] => 00020
)
)
使用array_column函数
$name_list = array_column($arr, 'id');
打印结果如下:
Array
(
[0] => 2188573
[1] => 2188572
[2] => 2149077
[3] => 1986569
)