Re: issues with ksort()

From: Date: Fri, 07 Feb 2003 17:18:51 +0000
Subject: Re: issues with ksort()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-134755@lists.php.net to get a copy of this message
On Fri, Feb 07, 2003 at 11:09:10AM -0600, Shawn McKenzie wrote: > > What else does ksort() do to the array??? Does it matter that my keys look > like this: '[some-text]'??? > > This works great: > > foreach($myarray as $key => $val) { > echo "$key = $val"; > } > > This gives me a Warning: Invalid argument supplied for foreach(): > > $sortedarray = ksort($myarray); > foreach($sortedarray as $key => $val) { > echo "$key = $val"; > } > > Any ideas??? Inserting a print_r into your test script tells you the problem, as does a closer look at http://www.php.net/ksort . You're assuming ksort()'s return value is the sorted array. It is not. Try something more along the lines of: $testarray=array( "[three]" => 3, "[two]" => 2, "[one]" => 1, ); ksort($testarray); print_r($testarray); -- Paul Chvostek <paul@it.ca> Operations / Abuse / Whatever it.canada, hosting and development http://www.it.ca/

« previous php.general (#134755) next »