Ok, here's the question:
If I have a number like 001 and I using PHP to add 1 to it, ex:
<?php $nmb = 001;
$nmb = nmb + 1; echo($nmb);
?>
Will it print "002" or just "2".
I hope you understood that. Thanks in advance.
Why don't you just run it?
it will print 2. leading zero's are never displayed.
in fact, initialising as $var = 001; is no different from $var = 1;
That will print 2. Any zeros before a non-string value will always be omitted.
Is there any way I can get a number from 009 to 010 for instance without having the numbers omitted?
Yes there is many ways but here is what i would do
<?php $var1 = 009; $var1++; print "00".$var1; /* mabye it is'nt perfect code but im just not sure what you would need this for if so mabye I could do better 🙂 hope this helps
*/ ?>
also take a look at the str_pad function
http://www.php.net/manual/en/function.str-pad.php
Or you can use sprintf to control out the number is outputted:
<? $num = 300; $num2 = sprintf("%06d", $num); echo "Original Number: " . $num; echo "<br>"; echo "Modified Number: " . $num2; ?>