'John, Middle Johnson',
'John, Johnson',
'Ann, Middle Mikelson',
'Ann, Mikelson',
];
$result = [];
foreach ($dataNames as $string) {
$items = explode(',', $string);
$first = array_shift($items);
$lastPart = array_shift($items);
$lastNames = explode(' ', trim($lastPart));
$lasName = $lastNames[1] ?? $lastNames[0];
$result[] = $first . ' ' . $lasName;
}
echo "<pre>";
print_r($result);
echo "</pre>";
exit('debug');
http://sandbox.onlinephpfunctions.com/code/a4ef9a118358a888b8c24cee3182a8160d8b331c На, студент регулярочник
Обсуждают сегодня