As a beginner in php, I'm in the situation where I have to reverse the followings strings:
- "secondname firstname" as "firstname secondame",
- "secondname1 secondname2 firstname" as "firstname secondname1 secondname2"
The code works but it looks like a little bit complicated for such a function.
$name = "secondname1 secondname2 firstname";
$split = explode(" ", $name);
$last = count($split);
$firstname = $split[$last -1];
$secondnames = implode(" ",array_slice($split,-$last, $last-1));
echo implode(" ",array($firstname, $secondnames));
Do you have any idea about something simpler ?