MutatedVirus Posted August 6, 2013 Share Posted August 6, 2013 Hey guys, I was wondering, how would I go about it so I can have a multi-dimensional array where the first value is a string, 2nd value is a minimum amount, 3rd value is a maximum amount.And then once having that being able to randomly select one of the strings (like using $a = rand(0,14); $test =$name[$a])but in conjunction being able to generate that string a random amount of times within the min and max without hvaing to use switch statements or if statements?If that is possible that is xDAnd if it is, I know it's not the most efficent way of doing this, it's just a project ive been given to do in this wayMany thanks for any helpJames :3 Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 6, 2013 Share Posted August 6, 2013 Seems like it might be homework, but oh well: $array = array(array('string1', 2, 10), array('string2', 5, 11), array('string3', 9, 25) ); $rand = mt_rand(0, count($array)-1); $word = $array[$rand][0]; $result = str_repeat($word, mt_rand($array[$rand][1], $array[$rand][2])); echo $result; Quote Link to comment Share on other sites More sharing options...
MutatedVirus Posted August 6, 2013 Author Share Posted August 6, 2013 Nah, it's not homework, it's just little challenges im being set in an apprenticeship im in, basically find ways on how to do it to learn how to code in PHP, but thanks, works like a charm ^^ Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 6, 2013 Share Posted August 6, 2013 Nah, it's not homework, it's just little challenges im being set in an apprenticeship im in, basically find ways on how to do it to learn how to code in PHP, but thanks, works like a charm ^^ Well that makes me feel better Make sure you learn something. Quote Link to comment Share on other sites More sharing options...
MutatedVirus Posted August 6, 2013 Author Share Posted August 6, 2013 I am learning stuff, It was just that I got stumped on xD But thanks for showing me how it works, it does help me learn more stuff 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.