Jump to content

[SOLVED] can this be written shorter?


Alkimuz

Recommended Posts

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.