Re: Switching First & Last Names in List

From: Date: Tue, 16 Mar 2004 16:24:12 +0000
Subject: Re: Switching First & Last Names in List
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-180562@lists.php.net to get a copy of this message
JO> so that the last name is first? Also, how do I JO> handle people with three names? Thanks.
I missed this part, so here's my take with the solution I provided (I'm including the print-out of the <option> tags): foreach ($name_array as $person) {
    $lastname_element = count($person) - 1; //index of last element
    echo "<option>" . $person[$lastname_element] . ", ";
    echo $person[0] . "</option>\n"; //zero (0) is the first name
} Ben Ramsey wrote:
This works rather nicely, too: <?php $list = "Firstname1 LastName1 Firstname2 Lastname2"; $name_array = array(); $temp_array = explode("\n", $list); foreach ($temp_array as $name) {
    $name_array[] = explode(" ", $name);
} print_r($name_array); ?> $name_array is now a multi-dimensional array with the first and last names separated. print_r should show you the values.
-- Regards, Ben Ramsey http://benramsey.com http://www.phpcommunity.org/wiki/People/BenRamsey

« previous php.general (#180562) next »