PHP SORT_NUMERIC
| From: | Jim Long | Date: | Fri, 28 Feb 2003 05:06:44 +0000 |
| Subject: | PHP SORT_NUMERIC | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-137513@lists.php.net to get a copy of this message | ||
Hi,
I've got to sort the $numeric_arry
This doesn't seem to work:
sort ($numeric_array, SORT_NUMERIC);
I think its sorting $key
asort ($numeric_array, SORT_NUMERIC);
sorts as a string
THANKS AGAIN IN ADVANCE,
Jim Long
JanetVal Wrote:
> Well, as long as you know exactly what you are looking for, you can use
>
> > if ($value != "n/a")) {
>
> Janet
Jason Lange Wrote:
> Try this code (tested):
>
> <---------- Begin Code ---------->
> foreach ($list as $key => $value) {
> // If elements value is a numeral add to numeric_array
> if (is_numeric($value)) {
> $numeric_array[$key] = $value;
> // If value is not a numeral (presumably 'n/a') add to na_array
> } else {
> $na_array [$key] = $value;
> }
> }
>
> // Re-combine arrays placing all "other" values at the end
> $final_array = array_merge($numeric_array, $na_array);
> <---------- End Code ---------->
Original Question:
>>>I have an array with an html link as key and different $vars as val:
>>>
>>>$list = array (
>>>'<a
>>>href="http://someplace.com/">some place</a>'
>>>=> $vendor1_total,
>>>'<a
>>>href="http://anotherplace.com/">another
>>>place</a>' =>
>
> $vendor2__total,
>
>>>[snip] etc..
>>>
>>>some vals are numeric and some vals are "n/a"
>>>asort works to sort the array as a string, however, I need to sort the
>>>numeric vals numeric, then have the n/a's go away or be output at the
>>>bottom of the sort.