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 Quote Link to comment 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); Quote Link to comment Share on other sites More sharing options...
ecopetition Posted January 10, 2009 Author Share Posted January 10, 2009 Thanks Russell Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted January 10, 2009 Share Posted January 10, 2009 $r = substr(rand(10000,19999),-4); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.