The PHP array_column() function returns an array that contains specific column values of the given array.
array_column(array, column_key, index_key);
The PHP array column function takes three parameters –
array
– An array.column_key
– The column name or key which you want to return.index_key
– It is an optional parameter. It is used to set a column value to the index key of the returning value.Example:
In the following example, we separate specific column values from an array (this array represents a possible recordset returned from a database).
Output : Array ( [0] => John [1] => Mark [2] => Barry [3] => Peter )
index_key Parameter Example :
Output :
Array
(
[5211] => web
[5421] => online
[6523] => alex
[7541] => Peter
)