Alkimuz Posted July 30, 2009 Share Posted July 30, 2009 just a little question, but hard to find an answer for: i have a variable with a lot of different possible values, and i want with some particular values run a script and with other not, i have the following code, which runs fine, but it looks so unnecessary long.. is it possible to shorten in down? if ($ID == 1 || $menuID ==5 || $menuID ==6 || $menuID ==7 || $menuID ==8 || $menuID ==9 || $menuID ==10 || $menuID ==21 || $menuID ==22 || $menuID ==23 || $menuID ==24 enz.. ) { code code code code } Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted July 30, 2009 Share Posted July 30, 2009 <?php $a = array("5","6","7","8","9","10","21","22","23","24"); if($id == 1 || in_array($menuID,$a)) { // do something } ?> I am not entirely sure if this is what you want since i was confused why $ID and $menuID are in the list, perhaps if you explain a little more what you are trying to do we can make it even simpler Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted July 30, 2009 Share Posted July 30, 2009 If you meant $menuID instead of $ID, then it would be more like this: <?php $menuArray = array(1, 5, 6, 7); if (in_array($menuID, $menuArray)) { echo 'Yabba Dabba'; } ?> Quote Link to comment Share on other sites More sharing options...
Alkimuz Posted July 31, 2009 Author Share Posted July 31, 2009 wouw, thanks guys! i indeed accidentally deleted the first 'menu' in menuID but the answer is perfect! thanks again! :D 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.