<?php
$phones = [
'Apple iPhone 4',
'Apple iPhone 5',
'Samsung Galaxy S6'
];
var_export(
array_reduce(
$phones,
function($result, $item) {
[
$key,
$result[$key][]
] = explode(' ', $item, 2);
return $result;
},
)
);
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- array (
'Apple' =>
array (
0 => 'iPhone 4',
1 => 'iPhone 5',
),
'Samsung' =>
array (
0 => 'Galaxy S6',
),
)
preferences:
125.76 ms | 402 KiB | 121 Q