<?php
$cities = ['New York', 'Boston', 'Los Angeles', 'Cincinnati', 'Chicago', 'Houston', 'Philadelphia', 'Dallas', 'Seattle'];
$result = [];
foreach ($cities as $city) {
$result[$city[0]][] = $city;
}
var_export($result);
- Output for 8.1.0 - 8.1.27, 8.1.29 - 8.1.33, 8.2.0 - 8.2.17, 8.2.19 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- array (
'N' =>
array (
0 => 'New York',
),
'B' =>
array (
0 => 'Boston',
),
'L' =>
array (
0 => 'Los Angeles',
),
'C' =>
array (
0 => 'Cincinnati',
1 => 'Chicago',
),
'H' =>
array (
0 => 'Houston',
),
'P' =>
array (
0 => 'Philadelphia',
),
'D' =>
array (
0 => 'Dallas',
),
'S' =>
array (
0 => 'Seattle',
),
)
- Output for 8.2.18
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.2.18/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.2.18/modules/sodium.so.so (/usr/lib/php/8.2.18/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array (
'N' =>
array (
0 => 'New York',
),
'B' =>
array (
0 => 'Boston',
),
'L' =>
array (
0 => 'Los Angeles',
),
'C' =>
array (
0 => 'Cincinnati',
1 => 'Chicago',
),
'H' =>
array (
0 => 'Houston',
),
'P' =>
array (
0 => 'Philadelphia',
),
'D' =>
array (
0 => 'Dallas',
),
'S' =>
array (
0 => 'Seattle',
),
)
- Output for 8.1.28
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.1.28/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.1.28/modules/sodium.so.so (/usr/lib/php/8.1.28/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array (
'N' =>
array (
0 => 'New York',
),
'B' =>
array (
0 => 'Boston',
),
'L' =>
array (
0 => 'Los Angeles',
),
'C' =>
array (
0 => 'Cincinnati',
1 => 'Chicago',
),
'H' =>
array (
0 => 'Houston',
),
'P' =>
array (
0 => 'Philadelphia',
),
'D' =>
array (
0 => 'Dallas',
),
'S' =>
array (
0 => 'Seattle',
),
)
preferences:
64.03 ms | 409 KiB | 5 Q