Author Topic: exception elseif statement, using array elements instead of a string  (Read 216 times)

0 Members and 1 Guest are viewing this topic.

Offline gwolgamottTopic starter

  • Enthusiast
  • Posts: 482
  • Gender: Male
  • Yes I am wrong at times... that is the difference.
    • View Profile
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
}
I sit in the seat of Gods In the midst of the seas.

Offline aeroswat

  • Devotee
  • Posts: 848
    • View Profile
Re: exception elseif statement, using array elements instead of a string
« Reply #1 on: February 09, 2010, 09:30:20 AM »
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

Offline gwolgamottTopic starter

  • Enthusiast
  • Posts: 482
  • Gender: Male
  • Yes I am wrong at times... that is the difference.
    • View Profile
Re: exception elseif statement, using array elements instead of a string
« Reply #2 on: February 09, 2010, 10:14:26 AM »
Thanks, exactly what I wanted.
I sit in the seat of Gods In the midst of the seas.