Re: [PHP] SORT_NUMERIC
On Friday 28 February 2003 23:28, Jim Long wrote: > Hi, > > Does anyone know how to make the flag "sort_numeric" work? > Will it work with asort? > > asort ($numeric_array, SORT_NUMERIC); > I've tried this but it looks like it's having problems with the comma in > big numbers. What comma in big numbers? Numbers aren't supposed to have commas. If it has a comma it's a string. > I'm not absolutely sure, but it looks like it's ignoring everything > after a comma when it sorts. Snippet from the manual "The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used.". As a comma is not valid numeric data, it and everything after, will be ignored. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* "It may be that our role on this planet is not to worship God but to create him." -Arthur C. Clarke */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] SORT_NUMERIC
Hi, Does anyone know how to make the flag "sort_numeric" work? Will it work with asort? asort ($numeric_array, SORT_NUMERIC); I've tried this but it looks like it's having problems with the comma in big numbers. I'm not absolutely sure, but it looks like it's ignoring everything after a comma when it sorts. TIA, Jim Long BTW: asort is the one I need as I must maintain the keys JanetVal Wrote: > sort() sorts by value but assigns new keys as numbers. > asort() sorts by value, but keeps the same keys > ksort() sorts by key. THANKS ! -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | Jim Long Network - Web Design | | http://jimlong.net/web | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | Jim Long - Rep: Manhattan Dance Orchestra | | http://manhattandanceorchestra.com | -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP SORT_NUMERIC
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 ( >>>'http://someplace.com/";>some place' => $vendor1_total, >>>'http://anotherplace.com/";>another place' => > > $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. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php