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
  • 11,924
  • 3
  • 21
  • 41
neptune
  • 1,171
  • 2
  • 18
  • 29

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
  • 17,880
  • 38
  • 105
  • 123
trenccan
  • 668
  • 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
  • 957
  • 14
  • 31
-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
  • 11