php array_column – PHP Array_column() Function Example

php array_column : PHP function array_column is built in PHP function. The array_column() function returns the values from a single array column in the input data array.

php array_column | array_column in php

PHP array_column() function returns an array that contains the values from the single column of an input array, identified by column_number.

The function array_column() is used to output the values from the input array by considering the single column of the input.

Sample Code – array_column in php

index.php

 10,
        'account_nm' => 'Virat',
        'slogen' => 'Dimple',
    ),
    array(
        'id' => 19,
        'account_nm' => 'Dinesh',
        'slogen' => 'Sangeeta',
    ),
    array(
        'id' => 50,
        'account_nm' => 'Rakesh',
        'slogen' => 'Dimple',
    ),
    array(
        'id' => 100,
        'account_nm' => 'Pratik',
        'slogen' => 'Shreyes',
    )
);
 
$accountNames = array_column($members, 'account_nm');
print_r($accountNames);
?>

Result

Array
(
    [0] => Virat
    [1] => Dinesh
    [2] => Rakesh
    [3] => Pratik
)

PHP 5. array_column doesn’t work with an array of objects. you can read Php Get Array Key By Value Multidimensional

To get the column of first names from with a index index


Result

Array
(
    [10] => Dimple
    [19] => Sangeeta
    [50] => Dimple
    [100] => Shreyes
)

I hope you get an idea about php array_column.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment