Created
August 24, 2022 19:06
-
-
Save AndrewSepic/78104481f076fcce1917f9277829a106 to your computer and use it in GitHub Desktop.
Take in First Name Last name and return Last Name, First Name Initial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function orderby_lastname ($legislator_name) { | |
$explodedName = explode(' ', $legislator_name); | |
if (count($explodedName) == 2) { | |
$lastNameFirst = array_reverse($explodedName); | |
$lastNameFirst = implode(' ', $lastNameFirst); | |
} else { | |
$lastName = array_pop($explodedName); | |
array_unshift($explodedName, $lastName); | |
$lastNameFirst = implode(' ', $explodedName); | |
} | |
return $lastNameFirst; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment