ItsWesYo Posted July 27, 2006 Share Posted July 27, 2006 [code]foreach($data as $name => $num){ $num = number_format($num); $name = ucfirst(strtolower($name)); $html .="{$name}: {$num}";[/code]Now. That code is for the total amount of pets. It displays each pet name with the total of each.Example: Pet 1 - 5,000 .... Pet 2 - 7,500How would I order the numbers from GREATEST to LEAST? Quote Link to comment https://forums.phpfreaks.com/topic/15833-petsite/ Share on other sites More sharing options...
gluck Posted July 27, 2006 Share Posted July 27, 2006 use the array sort functions. Quote Link to comment https://forums.phpfreaks.com/topic/15833-petsite/#findComment-64817 Share on other sites More sharing options...
ItsWesYo Posted July 28, 2006 Author Share Posted July 28, 2006 where would i put the 'SORT_NUMERIC' one at? Quote Link to comment https://forums.phpfreaks.com/topic/15833-petsite/#findComment-64931 Share on other sites More sharing options...
Ifa Posted July 28, 2006 Share Posted July 28, 2006 I think that rsort($data); will also do... :-\Come to think of it, it messes with the keys I think, so it won't work... :( Quote Link to comment https://forums.phpfreaks.com/topic/15833-petsite/#findComment-64979 Share on other sites More sharing options...
lukelambert Posted July 28, 2006 Share Posted July 28, 2006 Try arsort($data);. That will keep the keys intact.http://us2.php.net/manual/en/function.arsort.php Quote Link to comment https://forums.phpfreaks.com/topic/15833-petsite/#findComment-65015 Share on other sites More sharing options...
ItsWesYo Posted July 28, 2006 Author Share Posted July 28, 2006 So, it would look like this, I assume:[code]foreach($data as $name => $num){ $num = number_format($num); $name = ucfirst(strtolower($name)); $html .="{$name}: {$num} arsort($data);";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15833-petsite/#findComment-65350 Share on other sites More sharing options...
Barand Posted July 28, 2006 Share Posted July 28, 2006 Ummm , no.If you actually read that code and think about what's happening[code]get next array elementsort the arrayget next array elementsort the arrayget next array elementsort the arrayget next array elementsort the arrayget next array elementsort the arrayget next array elementsort the arrayget next array elementsort the array...etc[/code]then you might think "perhaps it's better to sort the array first then process the data in it."[code]arsort($data);foreach($data as $name => $num){ $num = number_format($num); $name = ucfirst(strtolower($name)); $html .= "$name: $num <br/>";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15833-petsite/#findComment-65460 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.