Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax question 2

Status
Not open for further replies.

Sleidia

Technical User
May 4, 2001
1,284
FR
Hi again ;)

Let's take the following if statement :

Code:
if ($a == 1 OR $a == 33 OR $a == 7) do_something();

Is it possible to do the same thing without repeating $a ?

Thanks for the help! :)
 
how about
Code:
if (in_array($a, array(1,7,33)){
 do_something();
}
 
Thanks Jpadie :)

... but it wouldn't work in the following case :

Code:
if ($a > 1 AND $a < 33 AND $a != 11) do_something();

We would still have to repeat $a.

Now, I think that if such a syntax existed, it couldn't be shorter than the current syntax anyway. I bet this is the reason why it wasn't implemented in PHP.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top