I have stock numbers that may contain a leading 0. For example:
0550
0551
0552
In efforts to find the next stock number, I do some simple addition:
$stock = '0552'; // This is found by querying the database
$nextstock = $stock + 1;
The problem is, $newstock
returns 553
- it removes the leading 0.
And I can't simply do something like this:
$nextstock = '0'.($stock + 1);
because not all the stock numbers will have leading zeros.
So, how do I increment a number that contains a leading 0 by 1 without removing the leading 0 and without forcing a leading 0 onto the variable, since they may not all have leading zeros?