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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.