Voting

: four plus one?
(Example: nine)

The Note You're Voting On

Sbastien
3 years ago
The counterpart of array_column(), namely create an array from columns, can be done with array_map() :

<?php

// Columns
$lastnames = ['Skywalker', 'Organa', 'Kenobi'];
$firstnames = ['Luke', 'Leia', 'Obiwan'];

// Columns to array
$characters = array_map(
fn (
$l, $f) => ['lastname' => $l, 'firstname' => $f],
$lastnames, $firstnames
);

print_r($characters);

/*
[
0 => ['lastname' => 'Skywalker', 'firstname' => 'Luke']
1 => ['lastname' => 'Organa', 'firstname' => 'Leia']
2 => ['lastname' => 'Kenobi', 'firstname' => 'Obiwan']
]
*/

<< Back to user notes page

To Top