Tidehunter Posted October 26, 2012 Share Posted October 26, 2012 (edited) I have a switch that uses a rand() to find the respective cases in between a number range, like so: switch($number = rand(1,10)) { case ($number > 1 && $number <= 5): doFunction(); break; case ($number > 5): doFunction(); break; } how would I use this in an array format? I find using switches to be clunky and limiting. I want to be able to do like: $array = array( 1-10 => 'value', 11-20 => 'value' ) Is this possible? Edited October 26, 2012 by Tidehunter Link to comment https://forums.phpfreaks.com/topic/269922-what-to-use-instead-of-a-mass-switch-case-randomly/ Share on other sites More sharing options...
ManiacDan Posted October 26, 2012 Share Posted October 26, 2012 That switch isn't even correct, that's not how switches work. The most efficient way to do this is with an if/elseif tree. Link to comment https://forums.phpfreaks.com/topic/269922-what-to-use-instead-of-a-mass-switch-case-randomly/#findComment-1387807 Share on other sites More sharing options...
Tidehunter Posted October 26, 2012 Author Share Posted October 26, 2012 That switch isn't even correct, that's not how switches work. The most efficient way to do this is with an if/elseif tree. Oh, well... apologies. It was a quick example not meant to be correct. Thank you anyways. Link to comment https://forums.phpfreaks.com/topic/269922-what-to-use-instead-of-a-mass-switch-case-randomly/#findComment-1387812 Share on other sites More sharing options...
ManiacDan Posted October 26, 2012 Share Posted October 26, 2012 If you have an actual question, go ahead and ask it. Your quick example was bad PHP code, and you haven't explained what you are trying to do. There isn't a great way for us to help you if you don't describe a problem or provide actual code to look at. Link to comment https://forums.phpfreaks.com/topic/269922-what-to-use-instead-of-a-mass-switch-case-randomly/#findComment-1387817 Share on other sites More sharing options...
Tidehunter Posted October 26, 2012 Author Share Posted October 26, 2012 If you have an actual question, go ahead and ask it. Your quick example was bad PHP code, and you haven't explained what you are trying to do. There isn't a great way for us to help you if you don't describe a problem or provide actual code to look at. Actually I did. My question was, is there another way to use a number range using arrays. You're telling me how switches work, yet you don't provide an example. You're telling me to provide actual code to look when I don't even know how to code it? rofl I wasn't looking forward to having an ass enter my thread, otherwise I'd just fart. Thanks for your god damn help. Link to comment https://forums.phpfreaks.com/topic/269922-what-to-use-instead-of-a-mass-switch-case-randomly/#findComment-1387904 Share on other sites More sharing options...
MDCode Posted October 26, 2012 Share Posted October 26, 2012 That's not a great way to get help Link to comment https://forums.phpfreaks.com/topic/269922-what-to-use-instead-of-a-mass-switch-case-randomly/#findComment-1387905 Share on other sites More sharing options...
Jessica Posted October 26, 2012 Share Posted October 26, 2012 (edited) Edit: Screw that, I just saw your nasty butt response to Dan, and I retract my help. Edited October 26, 2012 by Jessica Link to comment https://forums.phpfreaks.com/topic/269922-what-to-use-instead-of-a-mass-switch-case-randomly/#findComment-1387907 Share on other sites More sharing options...
ManiacDan Posted October 26, 2012 Share Posted October 26, 2012 Thread closed. Link to comment https://forums.phpfreaks.com/topic/269922-what-to-use-instead-of-a-mass-switch-case-randomly/#findComment-1387908 Share on other sites More sharing options...
Recommended Posts