在 PHP 中,array_column() 函數用于從多維數組中獲取指定列的值,并返回一個包含指定列值的數組。
語法:
array_column(array, column_key, index_key)
參數:
示例:
$students = [
['name' => 'Alice', 'age' => 20],
['name' => 'Bob', 'age' => 25],
['name' => 'Charlie', 'age' => 22]
];
$names = array_column($students, 'name');
print_r($names);
輸出:
Array
(
[0] => Alice
[1] => Bob
[2] => Charlie
)