All individual subscriptions are 50% off this week only!

dev740
1 month ago

Why is the loop printing wrong value?

Posted 1 month ago by dev740

echo($a[5]); //this is not printing 0 why?

 for($x=-2;$x<2.1;$x+=0.4){
 $a[] = $x*$x;

 }

Output is:

Array
(
    [0] => 4
    [1] => 2.56
    [2] => 1.44
    [3] => 0.64
    [4] => 0.16
    [5] => 1.2325951644078E-32
    [6] => 0.16
    [7] => 0.64
    [8] => 1.44
    [9] => 2.56
   [10] => 4
)

Please sign in or create an account to participate in this conversation.