ecopetition Posted January 10, 2009 Share Posted January 10, 2009 Hello, I'm wondering how I can make the number generated by "rand(0,9999)" always have 4 digits, so if the number 200 is generated, it displays 0200, but if the number 4000 is generated, it remains as 4000. I looked at the manual but didn't manage to find anything on this. Thanks a lot, Peter Link to comment https://forums.phpfreaks.com/topic/140296-number-display/ Share on other sites More sharing options...
RussellReal Posted January 10, 2009 Share Posted January 10, 2009 str_pad $r = rand(0,9999); $r = str_pad($r,4,'0',STR_PAD_LEFT); Link to comment https://forums.phpfreaks.com/topic/140296-number-display/#findComment-734110 Share on other sites More sharing options...
ecopetition Posted January 10, 2009 Author Share Posted January 10, 2009 Thanks Russell Link to comment https://forums.phpfreaks.com/topic/140296-number-display/#findComment-734129 Share on other sites More sharing options...
RussellReal Posted January 10, 2009 Share Posted January 10, 2009 please click SOLVED @ the bottom of the post Link to comment https://forums.phpfreaks.com/topic/140296-number-display/#findComment-734280 Share on other sites More sharing options...
Mark Baker Posted January 10, 2009 Share Posted January 10, 2009 $r = substr(rand(10000,19999),-4); Link to comment https://forums.phpfreaks.com/topic/140296-number-display/#findComment-734294 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.