You are here: Re: sorting array...i « PHP Programming Language « IT news, forums, messages
Re: sorting array...i

Posted by Steve on 11/20/07 16:04

"VooDoo" <VooDooNet38@free.fr> 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 '<pre>' . print_r($array, true) . '</pre>';
?>

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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация