php column in array to new array code example
Example 1: array_column in php
$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');
print_r($last_names);
Example 2: php collapse common columns in associative array
$result = array();
foreach ($data as $element) {
$result[$element['id']][] = $element;
}