Jump to content

[SOLVED] Float Associative Array


chrmlr

Recommended Posts

Is it possible to force float as the key for at least 2 decimals?

 

The code I have now is rounding the numbers down to integers. I want to keep them as floating point numbers.

 

 function rank()
{
$query="select * from ladder";
$result=mysql_query($query);
while ($row=mysql_fetch_assoc($result))
{
$ascarray[($row['win'] / $row['lose'])] = $row['userid'];
}
krsort($ascarray);
return $ascarray;

Link to comment
https://forums.phpfreaks.com/topic/78722-solved-float-associative-array/
Share on other sites

Thank you very much, that did the trick!

 

You can change your query to let MySQL do it and order it for you. Example:

 

$query="SELECT userid, win / lose AS avg_result FROM ladder ORDER BY avg_result ASC";

 

If you want results sorted by descending first, then change ASC to DESC.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.