array_column() 函数
从记录集中取出 last_name 列:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
输出“”
Array ( [0] => Gates [1] => Jobs [2] => Zuckerberg ) 从记录集中取出 last_name 列,用相应的 "id" 列作为键值:
<?php
// 表示由数据库返回的可能记录集的数组
$a = array(
array(
‘id‘ => 5698,
‘first_name‘ => ‘Bill‘,
‘last_name‘ => ‘Gates‘,
),
array(
‘id‘ => 4767,
‘first_name‘ => ‘Steve‘,
‘last_name‘ => ‘Jobs‘,
)
array(
‘id‘ => 3809,
‘first_name‘ => ‘Mark‘,
‘last_name‘ => ‘Zuckerberg‘,
)
);
$last_names = array_column($a, ‘last_name‘, ‘id‘)
;
print_r($last_names);
?>
输出:
Array ( [5698] => Gates [4767] => Jobs [3809] => Zuckerberg )注意:不返回莫一列,直接将全部数组返回,然后将元素值作为键名,中间字段为空
$newArray1 = array_column($data,NULL,‘uid‘);
原文地址:https://www.cnblogs.com/apolloren/p/12252692.html
时间: 2024-11-07 19:55:36