You achieved the same result as I, but in a different way. I also do
not see any non-complex way of reversing the names properly in all
cases. I think an extensive set of rules would have to be developed to
handle all of the different name formats out there. I suspect this is
beyond the scope of the question you have probably already satisfied
the requirements with what you've done.
Here is mine, just for an example of another method:
function lastNameFirst($name)
{
$lastName = trim(strrchr($name, " "));
$firstName = trim(rtrim($name, $lastName));
$reversedName = $lastName . ", " . $firstName;
return $reversedName;
}
-mark
On Mar 4, 10:20 pm, kristin robinson <
kaykay...@gmail.com> wrote:
> Hi folks, I confess I'm out of ideas.
>
> Our array has the following as authors:
>
> H. G. Wells
> Frank Herbert
> Ursula K. Le Guin
>
> In the real world in order to invert them I'd simply call the first
> and last names from the database and make them seperate items in the
> array. The only way I see to invert things for this exercise is to
> pick a character to break the string at. There's not always a
> period. So I search for spaces. If I look for the first space from
> the front H. G. Wells breaks wrong. First space from the back and
> Ursula K. Le Guin breaks wrong (her last name is Le Guin). And what
> if the array contained someone like Orson Scott Card (should be Card,
> Orson Scott) or J. R. R. Tolkein? There isn't a logic structure I can
> think of to figure out where the break is between first and last name
> that works every time.
>
> Any ideas welcome. You can see what I have athttp://
codepad.org/WTpnB2WX.