MrXander Posted March 12, 2008 Share Posted March 12, 2008 Hi guys, Need a little help, I currently have the following script: $num = 1; while ($num <= "385"){ echo $num; $num = $num + 1; } But what I need it to do is the following: 0001 0002 (plenty of numbers here) 0068 0069 0070 0071 (plenty of numbers here) 0123 (plenty of numbers here) 1234 etc etc. How can I do this? Any help would be appreciated!! Link to comment https://forums.phpfreaks.com/topic/95880-need-help-with-numbers/ Share on other sites More sharing options...
dotBz Posted March 12, 2008 Share Posted March 12, 2008 http://php.net/str_pad Link to comment https://forums.phpfreaks.com/topic/95880-need-help-with-numbers/#findComment-490862 Share on other sites More sharing options...
php_dave Posted March 12, 2008 Share Posted March 12, 2008 <?php $num = 1; while ($num <=1000) { printf("%04.0f",$num); echo("<BR />"); $num++; } ?> Link to comment https://forums.phpfreaks.com/topic/95880-need-help-with-numbers/#findComment-490865 Share on other sites More sharing options...
Barand Posted March 12, 2008 Share Posted March 12, 2008 or simply use '%04d' as the printf format string above for int values Link to comment https://forums.phpfreaks.com/topic/95880-need-help-with-numbers/#findComment-490873 Share on other sites More sharing options...
dotBz Posted March 12, 2008 Share Posted March 12, 2008 I got this: for ($i = 0; $i < 100; $i++) { echo str_pad($i, 4, "0", STR_PAD_LEFT) . "\n"; } Link to comment https://forums.phpfreaks.com/topic/95880-need-help-with-numbers/#findComment-490884 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.