-3

I am getting issue when increasing number.

For example:

 $r = 000123 //Integer

Now i want

 $r = 000124

I have try with multiple way.. but i didn't get the result. because of starting with 000.

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
Rajkeshar
  • 75
  • 10

2 Answers2

0

What if you try:

$r = 000123
$r++
Guilherme Lemmi
  • 3,271
  • 7
  • 30
  • 30
0

You can do it this way

$num = "00000123";

// get number without zero prefix
preg_match('/(?!0+)\d+/', $num, $match);

// increase by 1
$match[0]++;

// add zero prefix
$newNum = sprintf('%08d', $match[0]);

var_dump($newNum);
daremachine
  • 2,678
  • 2
  • 23
  • 34