Skip to content

Instantly share code, notes, and snippets.

@AndrewSepic
Created August 24, 2022 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewSepic/78104481f076fcce1917f9277829a106 to your computer and use it in GitHub Desktop.
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
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