Date Added: 14/01/2015

http://www.php.net/manual/en/function.array-column.php


$first_names = array_column($records, 'first_name');


<!--?php <br ?-->// Array representing a possible record set returned from a database
$records = array(
array(
'id' => 2135,
'first_name' => 'John',
'last_name' => 'Doe',
),
array(
'id' => 3245,
'first_name' => 'Sally',
'last_name' => 'Smith',
),
array(
'id' => 5342,
'first_name' => 'Jane',
'last_name' => 'Jones',
),
array(
'id' => 5623,
'first_name' => 'Peter',
'last_name' => 'Doe',
)
);

$first_names = array_column($records, 'first_name');
print_r($first_names);
?>
Array
(
    [0] => John
    [1] => Sally
    [2] => Jane
    [3] => Peter
)

<!--?php
// Using the $records array from Example #1
$last_names = array_column($records, 'last_name', 'id');
print_r($last_names);
?-->

Array
(
    [2135] => Doe
    [3245] => Smith
    [5342] => Jones
    [5623] => Doe
)

Last Update: Posted by: müslüm ÇEN
Not Commented Yet !
Please login in order to comment . Login