key arrays should be integers when they are not what's happening exactly?
| From: | Negin Nickparsa | Date: | Mon, 21 Jul 2014 00:22:33 +0000 |
| Subject: | key arrays should be integers when they are not what's happening exactly? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-323636@lists.php.net to get a copy of this message | ||
Hi
how PHP rounds the numbers in this case ?
$a = array(
0.5 => 1,
0.8 => 2,
1.2 => 3,
1.8 => 4,
);
print_r($a);
echo round(0.5);
we cannot have float keys so they will be rounded but I am wondering for
example rounding 0.5 will return 1 so from 0.1 to 0.4 all will be rounded
to 0
so it seems it is not doing the logic like the round function because the
$a output is :
Array ( [0] => 2 [1] => 4 )
what is the logic here?
Sincerely
Negin Nickparsa