| Welcome to WebmasterWorld Guest from 126.96.36.199 |
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
|Pubcon Platinum Sponsor 2014|
|Addition with php|
problem with zero's
| 11:05 pm on Sep 8, 2002 (gmt 0)|
I have a function that takes a var and adds 1
The problem is this:
The var starts as 01, I need to add 1 and have the output be 02 and so on untill 10 when the begining 0 will be dropped.
I am still new to PHP and some help with this one.
This is what I am using now:
<? $new-var = $some-var + 01 ?>
Thanks in advance,
| 11:21 pm on Sep 8, 2002 (gmt 0)|
Test to see if $newvar is less then 2 digits.
$newvar = "0" . $newvar;
| 11:29 pm on Sep 8, 2002 (gmt 0)|
That did the trick.
| 11:38 pm on Sep 8, 2002 (gmt 0)|
$var = sprintf [php.net]("%02d", $var);
would work as well.
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved