FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Filling an array with random input doesn't quite work
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: solved! Re: Filling an array with random input doesn't quite work (was: Filling an array with random input doesn't quite work) [message #185222 is a reply to message #185217] Thu, 13 March 2014 02:50 Go to previous messageGo to previous message
Doug Miller is currently offline  Doug Miller
Messages: 171
Registered: August 2011
Karma:
Senior Member
Tim Streater <timstreater(at)greenbee(dot)net> wrote in news:120320142249386192%
timstreater(at)greenbee(dot)net:

> In article <85dkidwa0h67(dot)ecj3ezgrqtzk$(dot)dlg(at)40tude(dot)net>, richard
> <noreply(at)example(dot)com> wrote:
>
> You're welcome.
>
>> $x=1;
>> while ($x<40){
>> $yr=rand(1,10);
>> $yr=$yr+59;
>>
>> $num=rand(1,100);
>> if ($num<100){$num="0".$num;}
>> if ($num<10){$num="0".$num;}
>
> What is the point if this second "if"? You've already covered that with
> the first.

No, he hasn't. The point is to pad $num on the left with zeros to a consistent length of 3
characters. Values less than 100 are padded with a zero; values less than 10 are padded
again -- so anything between 1 and 9 inclusive gets two padding characters, and values
from 10 to 99 get only one.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: readdir lists randomly
Next Topic: Nested PHP
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 18:53:38 GMT 2024

Total time taken to generate the page: 0.04947 seconds