Sort Array not working

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux