froehoel
11/14/2018 - 10:15 PM

Php

Split fullname to lastname and firstname

$fullName = "Jens Morten Bøthun Frøhoel";

function lastName_from_fullName($fullName)
{
    $names = explode(' ', trim($fullName));
    return $names[count($names)];
}

function nameParts_from_fullName($fullName)
{
    $names = explode(' ', trim($fullName));
    return ['lastname' => array_pop($names), 'firstname' => implode(' ', $names)];
}