shamuraq Posted June 4, 2009 Share Posted June 4, 2009 Hi guys... I'm trying to randomise symbolic character (eg; #). Can anyone spot any problem in my code? Its easy to echo them out immediately but I need to store the number of symbols parsed into a variable first before i echo them out. <?php $a = rand(10,20); for($b = 0; $b < $a; $b++){ $x = '#'; $x1 = array($x); } echo "$x1()"; ?> Can't seem to get it working... Thanx in advance Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 4, 2009 Share Posted June 4, 2009 I have no idea what you're trying to do. Why do you even need the for loop? FWIW, str_repeat would do the same thing as that code there. Quote Link to comment Share on other sites More sharing options...
shamuraq Posted June 4, 2009 Author Share Posted June 4, 2009 I'm trying to produce '#' randomly... Quote Link to comment Share on other sites More sharing options...
RClapham Posted June 4, 2009 Share Posted June 4, 2009 An example using Ken2k7's suggestion: <?php // Random number $rand = rand(10,20); // Repeat x times $str = str_repeat("#",$rand); // Echo the result, should be #the number of times the random number is set to. echo $str; ?> Quote Link to comment Share on other sites More sharing options...
shamuraq Posted June 4, 2009 Author Share Posted June 4, 2009 Thanx RClapham Quote Link to comment Share on other sites More sharing options...
shamuraq Posted June 4, 2009 Author Share Posted June 4, 2009 I have no idea what you're trying to do. Why do you even need the for loop? FWIW, str_repeat would do the same thing as that code there. That's why you're the pro and i'm the newbie. Btw, if you want to reply with such arrogance, don't trouble yourself. Or are you just trying to raise you reply posts to move up the ranks? Lolxxx... you rock man!!! I've noted your replies on a couple of posts... 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.