sorting array...i

sorting array...i

am 20.11.2007 16:32:13 von Voodoo

Hi,
I am getting confused with sorting arrays...
$arraytest =array(5) { [0]=> string(2) "39" [1]=> string(2) "44" [2]=>
string(2) "77" [3]=> string(3) "150" [4]=> string(3) "464" }

why do i get NULL value if i try to sort this array using sort command?

sort($arraytest);


Thanks for your help!
VooDoo

Re: sorting array...i

am 20.11.2007 17:04:56 von Steve

"VooDoo" wrote in message
news:fhuulb$72s$1@reader1.imaginet.fr...
> Hi,
> I am getting confused with sorting arrays...
> $arraytest =array(5) { [0]=> string(2) "39" [1]=> string(2) "44" [2]=>
> string(2) "77" [3]=> string(3) "150" [4]=> string(3) "464" }
>
> why do i get NULL value if i try to sort this array using sort command?
>
> sort($arraytest);

poorly asked question.

sort() performs a sort on the $array parameter by reference. sort() does NOT
return the sorted version of $array as a result of its operation. so...

$array = array(
'39' ,
'44' ,
'77' ,
'150' ,
'464'
);
sort($array);
echo '

' . print_r($array, true) . '
';
?>

will print the array and show that the values are sorted from lowest to
highest.

btw, leave out the array(5) string(2) [0]=> shit. it makes reading the code
a pain in the ass and isn't needed in the least...it doesn't make any impact
on the way php executes that code. if coded like the above, you can easily
see what *actual* values are making up the members of the array...rather
than trying to weed out the other junk surrounding them (like what index it
has or what data-type you are *casting* it to). the extra crap is feckless
and less than useful.

Re: sorting array...i

am 20.11.2007 17:50:57 von luiheidsgoeroe

On Tue, 20 Nov 2007 16:32:13 +0100, VooDoo wrote:

> Hi,
> I am getting confused with sorting arrays...
> $arraytest =3Darray(5) { [0]=3D> string(2) "39" [1]=3D> string(2) "44"=
[2]=3D>
> string(2) "77" [3]=3D> string(3) "150" [4]=3D> string(3) "464" }
>
> why do i get NULL value if i try to sort this array using sort command=
?
>
> sort($arraytest);

Probably, because sort() works by reference, not return:

$arraytest =3D sort($arraytest);
//=3D>$arraytest =3D true or false; $arraytest[N] =3D NULL

sort($arraytest);
//=3D>$arraytest =3D sorted array; $arraytest[N] =3D set value or NULL i=
f =

non-existant
-- =

Rik Wasmus

Re: sorting array...i

am 21.11.2007 10:42:44 von Voodoo

Ok thanks for your replies.
So the sort its working, I do not need to affect it to a var, just call the
function...

Sorry for the extra crap it was the outpout of a var_dump as i could not
understand what was wrong.
Thanks
Voodoo

Re: sorting array...i

am 21.11.2007 18:46:59 von Steve

"VooDoo" wrote in message
news:fi0ui3$e98$1@reader1.imaginet.fr...
> Ok thanks for your replies.
> So the sort its working, I do not need to affect it to a var, just call
> the function...

right.

> Sorry for the extra crap it was the outpout of a var_dump as i could not
> understand what was wrong.
> Thanks

no problem.