Your Location is: Home > Php

PHP for loop long number considered as float

From: India View: 4900 Zack 
 php

Question

I'm having an issue with PHP for loop, if the initial point number is too long, it will be considered as Float, how to solve it?

for ($i=3435764359345435874356345973457392; $i <= 7674664832038037428010029546434709302726; $i++) { 
  Code
}

This will output an error "3.8338983631591E+74" can't open the resource.

How to force it to consider it as an integer no matter what the longest number is.

Best answer

You can use the strval() function to convert a number to a string. but in your case It's been suggested to use GNU Multiple Precision, but that's not enabled in PHP by default.

$int=gmp_init("10000000000000000000000000");
$string=gmp_strval($int);
echo $string;