poe Posted November 21, 2006 Share Posted November 21, 2006 i just cant seem to remember how to pad a numberie make '3' into '03'ormake '22' into '00022' Link to comment https://forums.phpfreaks.com/topic/27943-pad-a-number/ Share on other sites More sharing options...
doni49 Posted November 21, 2006 Share Posted November 21, 2006 $i = 3;$i = "0" . $i;$k = 22;$k = "000" . $k; Link to comment https://forums.phpfreaks.com/topic/27943-pad-a-number/#findComment-127810 Share on other sites More sharing options...
kenrbnsn Posted November 21, 2006 Share Posted November 21, 2006 Use the [url=http://www.php.net/sprintf]sprintf()[/url] function.[code]<?phpfor($i=0;$i<10;$i++) echo sprintf("%05d",rand(1,1000)).'<br>';?>[/code]The above code will print ten random numbers between 1 and 1000 padded to 5 characters with zeros.Ken Link to comment https://forums.phpfreaks.com/topic/27943-pad-a-number/#findComment-127813 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.