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 } Link to comment https://forums.phpfreaks.com/topic/168214-solved-can-this-be-written-shorter/ 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 Link to comment https://forums.phpfreaks.com/topic/168214-solved-can-this-be-written-shorter/#findComment-887260 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'; } ?> Link to comment https://forums.phpfreaks.com/topic/168214-solved-can-this-be-written-shorter/#findComment-887261 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 Link to comment https://forums.phpfreaks.com/topic/168214-solved-can-this-be-written-shorter/#findComment-887598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.