Get the column of first names from a recordset in core php 7


<?php
// Array representing a possible record set returned from a database
$records = array(
    array(
        'id' => 1,
        'first_name' => 'Ajay',
        'last_name' => 'Jain',
    ),
    array(
        'id' => 2,
        'first_name' => 'Saurabh',
        'last_name' => 'Seth',
    ),
    array(
        'id' => 3,
        'first_name' => 'Abhshank',
        'last_name' => 'Kumar',
    ),
    array(
        'id' => 4,
        'first_name' => 'Rakesh',
        'last_name' => 'Thakur',
    )
);
 
$first_names = array_column($records, 'first_name');
print_r($first_names);
?>


Result Set

Array
(
    [0] => Ajay
    [1] => Saurabh
    [2] => Abhshank
    [3] => Rakesh
)

Leave a Reply

Your email address will not be published. Required fields are marked *