Sort Array not working
| From: | Kevin Murphy | Date: | Tue, 09 Jan 2007 18:41:17 +0000 |
| Subject: | Sort Array not working | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-246808@lists.php.net to get a copy of this message | ||
I'm having trouble sorting an array. When I do, it empties the array for some reason. Take the following code:
$data = "bird,dog,cat,dog,,horse,bird,bird,bird,lizard";
$array = explode(",",$data); // Create the array
$array = array_diff($array, array("")); // Drop the empty elements
$array = array_unique($array); // Drop the duplicate elements
$array = array_merge($array); // Reset the array keys
print_r ($array);
Up to here it works great. The resulting output is:
Array ( [0] => bird [1] => dog [2] => cat [3] => horse [4] => lizard )
Then if I do this:
$array = sort($array); // Sorts the array
print_r ($array);
The output is "1". I've tried asort, rsort in the place of sort and get the same results. I've also tried putting the sort in between the first 4 steps and that doesn't work either. Obviously I'm doing something wrong here. I'm using PHP 4.3.4. Any suggestions?
--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326