Jump to content

exception elseif statement, using array elements instead of a string


gwolgamott

Recommended Posts

How do I make that piece of code more efficient, for lack of a better word I guess?

Meaning so I can store a chunk of exceptions in an array then have it just check $element against any one of the array elements. I'm pretty sure I've done this before but for the life of me can not think of it and I must be searching for the wrong thing to find what I am looking for elsewhere...

elseif ($element!= "." && $element!= ".." && $element!= "struct.php" && $element!= "index.php" && $element!= "index.htm" && $element!= "index.html") 
{
//do whatever here
}

How do I make that piece of code more efficient, for lack of a better word I guess?

Meaning so I can store a chunk of exceptions in an array then have it just check $element against any one of the array elements. I'm pretty sure I've done this before but for the life of me can not think of it and I must be searching for the wrong thing to find what I am looking for elsewhere...

elseif ($element!= "." && $element!= ".." && $element!= "struct.php" && $element!= "index.php" && $element!= "index.htm" && $element!= "index.html") 
{
//do whatever here
}

 

Checking to see if $element is one of those? So those strings would be in the array? If so you could use array_intersect http://us2.php.net/array_intersect

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.