array column zamiast pętli

<?php
// 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', 'id');
print_r($first_names);
       
//=================

foreach ($result as $status) {
    $statuses[$status['id']] = sprintf('%s [%s]', $status['name'], $status['id']);
}

return $statuses;
        
return array_column($result, 'name', 'id');
Komentarze wyłączone