onedumbcoder Posted May 23, 2008 Share Posted May 23, 2008 I am trying to create a number with this formate 0101 and incremented like this 0201 0301 0402 0502 0602..... so i do i create something what will maintain that. when i did this $a = 01; $b = 01; $a++; $b++ $tracker = $a . $b i get 22 Link to comment https://forums.phpfreaks.com/topic/106972-solved-leading-zero-if-less-then-10/ Share on other sites More sharing options...
947740 Posted May 23, 2008 Share Posted May 23, 2008 Make 0 a string and not a number. so, $zero = "0"; $a = 1; $b = 1; $a++; $b++; $tracker = $zero . $a . $zero . $b; You would need an if statement to check if $a and $b are less than 0, and display $zero if they are. Link to comment https://forums.phpfreaks.com/topic/106972-solved-leading-zero-if-less-then-10/#findComment-548309 Share on other sites More sharing options...
effigy Posted May 23, 2008 Share Posted May 23, 2008 <pre> <?php $a = 1; $b = 22; printf('%02d%02d', $a, $b); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/106972-solved-leading-zero-if-less-then-10/#findComment-548314 Share on other sites More sharing options...
onedumbcoder Posted May 23, 2008 Author Share Posted May 23, 2008 can i do $tracker = printf('%02d%02d', $a, $b); Link to comment https://forums.phpfreaks.com/topic/106972-solved-leading-zero-if-less-then-10/#findComment-548326 Share on other sites More sharing options...
effigy Posted May 23, 2008 Share Posted May 23, 2008 Use sprintf to return a string. Link to comment https://forums.phpfreaks.com/topic/106972-solved-leading-zero-if-less-then-10/#findComment-548331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.