Reputation: 211
I have an array like this, returned by MySQL:
array(0 => array('123', 'data'), 1 => array('124', 'data2'));
Now I want to transform it into this without doing any loops through an array:
array('123' => 'data', '124' => 'data2');
Upvotes: 0
Views: 60
Reputation: 212412
$data = array(0 => array('123', 'data'), 1 => array('124', 'data2'));
$newdata = array_combine( array_map( function( $item ) {
return $item[0];
},
$data
),
array_map( function( $item ) {
return $item[1];
},
$data
)
);
var_dump($newdata);
Upvotes: 1