Edit report at http://bugs.php.net/bug.php?id=54248&edit=1
ID: 54248 Updated by: [email protected] Reported by: rodoeted at yahoo dot com Summary: disappearing array key [987] -Status: Open +Status: Bogus Type: Bug Package: Output Control Operating System: centos 5.5 PHP Version: 5.3.5 Block user comment: N Private report: N New Comment: Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. If you would like to know more about "floats" and what IEEE 754 is, read this: http://www.floating-point-gui.de/ Thank you for your interest in PHP. . Previous Comments: ------------------------------------------------------------------------ [2011-03-14 15:48:30] rodoeted at yahoo dot com Description: ------------ the key 987 disappears Test script: --------------- $ceva=array( array('amount'=>9.89), array('amount'=>9.88), array('amount'=>9.87), array('amount'=>9.86), array('amount'=>9.85), array('amount'=>9.84), array('amount'=>9.83), array('amount'=>9.82), array('amount'=>8.86), array('amount'=>8.85), array('amount'=>8.84), ); function print_a($array) { echo "<pre>"; print_r($array); echo "</pre>"; } print_a($ceva); $usable=array(); foreach($ceva as $b){ $x=$b['amount']*100; $usable[$x]=$b['amount']; var_dump($usable[$x]); } var_dump($usable); Expected result: ---------------- <pre>Array ( [0] => Array ( [amount] => 9.89 ) [1] => Array ( [amount] => 9.88 ) [2] => Array ( [amount] => 9.87 ) [3] => Array ( [amount] => 9.86 ) [4] => Array ( [amount] => 9.85 ) [5] => Array ( [amount] => 9.84 ) [6] => Array ( [amount] => 9.83 ) [7] => Array ( [amount] => 9.82 ) [8] => Array ( [amount] => 8.86 ) [9] => Array ( [amount] => 8.85 ) [10] => Array ( [amount] => 8.84 ) ) </pre>float(9.89) float(9.88) float(9.87) float(9.86) float(9.85) float(9.84) float(9.83) float(9.82) float(8.86) float(8.85) float(8.84) array(10) { [989]=> float(9.89) [988]=> float(9.88) [987]=> float(9.87) [986]=> float(9.86) [985]=> float(9.85) [984]=> float(9.84) [983]=> float(9.83) [982]=> float(9.82) [886]=> float(8.86) [885]=> float(8.85) [884]=> float(8.84) } Actual result: -------------- <pre>Array ( [0] => Array ( [amount] => 9.89 ) [1] => Array ( [amount] => 9.88 ) [2] => Array ( [amount] => 9.87 ) [3] => Array ( [amount] => 9.86 ) [4] => Array ( [amount] => 9.85 ) [5] => Array ( [amount] => 9.84 ) [6] => Array ( [amount] => 9.83 ) [7] => Array ( [amount] => 9.82 ) [8] => Array ( [amount] => 8.86 ) [9] => Array ( [amount] => 8.85 ) [10] => Array ( [amount] => 8.84 ) ) </pre>float(9.89) float(9.88) float(9.87) float(9.86) float(9.85) float(9.84) float(9.83) float(9.82) float(8.86) float(8.85) float(8.84) array(10) { [989]=> float(9.89) [988]=> float(9.88) [986]=> float(9.86) [985]=> float(9.85) [984]=> float(9.84) [983]=> float(9.83) [982]=> float(9.82) [886]=> float(8.86) [885]=> float(8.85) [884]=> float(8.84) } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54248&edit=1
