在 PHP 中,array_column() 函數(shù)用于從多維數(shù)組中獲取指定列的值,并返回一個包含指定列值的數(shù)組。
語法:
array_column(array, column_key, index_key)
參數(shù):
示例:
$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
)