PHP Array column() Function

6 Jan 2025 | 2 min read

It is an inbuilt function in PHP. The array_column() function is used to return the values from a single column in the input array. This function is introduced in PHP 5.5.

Syntax

ParameterDescriptionIs compulsory
arraySpecifies the multi-dimensional array to usecompulsory
Column_keyThis parameter may be an integer or a string key name of the column of values to return. It may also be NULL to return complete arrays (useful together with index_key to re-index the array)compulsory
index_keyThis parameter may be an integer key or a string key name of the column. It is used to provide the index/keys for the returned arrayoptional

Example 1

Output:

 Array( [0] => sid [1] => sonoo ) 

Example 2

Output:

 Array ( [0] => c [1] => java [2] => php ) 

Example 3

Output:

 Array ( [11] => c [12] => php [13] => java ) 

Example 4

Output:

 Array ( [0] => Cricket [1] => Football [2] => Chess )