Combining Multiple Columns into One Array using array_column() with PHP 8.4

You can also use array_column to extract values from multiple columns if you need them together. For example, let’s extract both the name and email fields into a new associative array.

<?php 
$namesAndEmails = array_map(function ($user) {
return [
'name' => $user['name'],
'email' => $user['email'],
];
},
$users);
print_r($namesAndEmails);
?>
<?phpArray
(
[name] => John
[email] => john@example.com
)
[1] => Array
(
[name] => Jane
[email] => jane@example.com
)
[2] => Array
(
[name] => Alice
[email] => alice@example.com
)
)
?>

In this case, we’re combining name and email into a new array, which requires array_map instead of array_column. You could use array_column for simpler tasks where only one column is needed.