0

I'd like an incremented $max_id to be returned.

Seems that the following script doesn't work:

<?php
$max_id = 656886639189471232;
$max_id = $max_id+1;
$max_id = number_format($max_id, 0, '', '');
var_dump($max_id);
?>

Needed 656886639189471233

Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41
neptune
  • 1,211
  • 2
  • 19
  • 32

3 Answers3

2

Try this:

<?php
$a = "656886639189471232";
$b = "1";

echo bcadd($b, $a,0);
?>

If your input data are integers you can convert $a and $b to string with:

$var=5;
$tostring = strval($var);
echo var_dump($tostring);
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
trenccan
  • 720
  • 3
  • 7
  • 19
0

The problem is number_format is made for float.

You can have details on this other post Why is my number value changing using number_format()?

Community
  • 1
  • 1
Michael
  • 1,063
  • 14
  • 32
-1

Remove the following line:

$max_id = number_format($max_id, 0, '', '');

The following works fine:

$max_id = 656886639189471232;
$max_id = $max_id+1;
var_dump($max_id);
Pharm
  • 152
  • 1
  • 12