sort the array
Moderator: General Moderators
sort the array
how to sort the contents of an array in ascending and descending order?
Re: sort the array
assume the input is either a string or a number.how do i obtain the output for descending as well as ascending order in one command ?i have used the command asort for ascending and arsort for descending,but this works only for strings.For numbers,this doesnt work.can u pls give me one command which works for strings as well as for numbers. ?kindly help.
Re: sort the array
sort, rsort, asort, and arsort work for numbers too. You'd know that if you bothered looking at the manual page for any of them.
Re: sort the array
Pay attention to the sorting options, SORT_NUMERIC - in particular.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Re: sort the array
Code: Select all
$str=explode("\n",$str);
sort($str);
It works for strings coorectly but not for numbers.
FOR eg:
10
11
1
2
This is the output :
1
10
11
2
Re: sort the array
scottayy wrote:Pay attention to the sorting options, SORT_NUMERIC - in particular.
Re: sort the array
You will want to look into using PHP's natural sorting. http://us.php.net/natsort