Get column of last names from a recordset, indexed by the "id" column in PHP
Description
The following code shows how to get column of last names from a recordset, indexed by the "id" column.
Example
//from w w w. jav a 2s. com
<?php
// An array that represents a possible record set returned from a database
$a = array(
array(
'id' => 1,
'first_name' => 'XML',
'last_name' => 'HTML',
),
array(
'id' => 2,
'first_name' => 'HTML',
'last_name' => 'CSS',
),
array(
'id' => 3,
'first_name' => 'CSS',
'last_name' => 'Java',
)
);
$last_names = array_column($a, 'last_name', 'id');
print_r($last_names);
?>
The code above generates the following result.