• 实例首页
  • 自学教程
  • IT工具箱
xxxxxxxxxx
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<title>PHP array_column() 函数 实例 - 自学教程(runoops.com)</title>
6
</head>
7
<body>
8
​
9
<?php
10
// 可能从数据库中返回数组
11
$a = [
12
  [
13
    'id' => 5698,
14
    'first_name' => 'Peter',
15
    'last_name' => 'Griffin',
16
  ],
17
  [
18
    'id' => 4767,
19
    'first_name' => 'Ben',
20
    'last_name' => 'Smith',
21
  ],
22
  [
23
    'id' => 3809,
24
    'first_name' => 'Joe',
25
    'last_name' => 'Doe',
26
  ]
27
];
28
​
29
$last_names = array_column($a, 'last_name');
30
echo '<pre>';
31
var_dump($last_names);
32
echo '</pre>';
33
?>
34
​
35
</body>
36
​
37
</html>