Toggle navigation
Home
Latest pastes
FAQ
Random
Register
Login
Get column of last names from a recordset, indexed by the "id" column:
SUBMITTED BY:
henry1874w
DATE:
June 22, 2017, 12:10 a.m.
FORMAT:
Text only
SIZE:
539 Bytes
Raw
Download
Tweet
HITS:
291
Go to comments
Report
<?php
// An array that represents a possible record set
returned from a database
$a = array(
array(
'id' => 5698,
'first_name' => 'Peter',
'last_name' => 'Griffin',
),
array(
'id' => 4767,
'first_name' => 'Ben',
'last_name' => 'Smith',
),
array(
'id' => 3809,
'first_name' => 'Joe',
'last_name' => 'Doe',
)
);
$last_names = array_column($a, 'last_name', 'id');
print_r($last_names);
?>
Output:
Array
(
[5698] => Griffin
[4767] => Smith
[3809] => Doe
)
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus