<?php
$data = '|> Томмот|Якутия|
|> Удачный|Якутия|
|> Якутск|Якутия|
|> Губкинский|Ямало-Ненецкий авт. окр.|';
$lines = explode("\n", $data);
$items = array_map(function($line) {
$cells = explode('|', substr($line, 3));
return ['city' => $cells[0], 'area' => $cells[1]];
}, $lines);
var_dump($items);
- Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.4, 8.3.6 - 8.3.14, 8.4.1
- array(4) {
[0]=>
array(2) {
["city"]=>
string(12) "Томмот"
["area"]=>
string(12) "Якутия"
}
[1]=>
array(2) {
["city"]=>
string(14) "Удачный"
["area"]=>
string(12) "Якутия"
}
[2]=>
array(2) {
["city"]=>
string(12) "Якутск"
["area"]=>
string(12) "Якутия"
}
[3]=>
array(2) {
["city"]=>
string(20) "Губкинский"
["area"]=>
string(43) "Ямало-Ненецкий авт. окр."
}
}
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array(4) {
[0]=>
array(2) {
["city"]=>
string(12) "Томмот"
["area"]=>
string(12) "Якутия"
}
[1]=>
array(2) {
["city"]=>
string(14) "Удачный"
["area"]=>
string(12) "Якутия"
}
[2]=>
array(2) {
["city"]=>
string(12) "Якутск"
["area"]=>
string(12) "Якутия"
}
[3]=>
array(2) {
["city"]=>
string(20) "Губкинский"
["area"]=>
string(43) "Ямало-Ненецкий авт. окр."
}
}
preferences:
79.68 ms | 409 KiB | 5 Q