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 Link to comment https://forums.phpfreaks.com/topic/160919-solved-randomise-array/ 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. Link to comment https://forums.phpfreaks.com/topic/160919-solved-randomise-array/#findComment-849224 Share on other sites More sharing options...
shamuraq Posted June 4, 2009 Author Share Posted June 4, 2009 I'm trying to produce '#' randomly... Link to comment https://forums.phpfreaks.com/topic/160919-solved-randomise-array/#findComment-849237 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; ?> Link to comment https://forums.phpfreaks.com/topic/160919-solved-randomise-array/#findComment-849266 Share on other sites More sharing options...
shamuraq Posted June 4, 2009 Author Share Posted June 4, 2009 Thanx RClapham Link to comment https://forums.phpfreaks.com/topic/160919-solved-randomise-array/#findComment-849333 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... Link to comment https://forums.phpfreaks.com/topic/160919-solved-randomise-array/#findComment-849336 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.