Possible Duplicate:
php if statement with multiple conditions
I have this code:
if(x==1 || x==2 || x==3 || x==4 )
Is there anyway to simply it shorter? For example:
if(x==1||2||3||4 )
Meaning for the statement to be true if X= 1,2,3 OR 4?
Thank you in advance.
Edit: (Thanks for all the replies, here is some clarification)
I have a while loop but only want specific database entries to be called. My code is current
<?php while(the_repeater_field('team_members','options') && get_sub_field('member_sort') == 1 : ?>
<div class="one_fourth">
<img src="<?php the_sub_field('image'); ?>" alt="" />
<p>
<?php the_sub_field('info'); ?>
<br />
<a href="mailto:<?php the_sub_field('email'); ?>"><?php the_sub_field('email'); ?></a>
</p>
</div>
<?php endwhile; ?>
Right now it works perfectly with == 1 , but I also want to show 2,3,4 as well. I am just not sure how I should’ve put the code to execute 1||2||3||4
Update 2:
Okay so I used the following code, but I am guessing I am going about it the wrong way. The following code only showed the record that was equal to 1.. but not the records equal to 2,3,4… I am guess because the while loop is only running once since the statement becomes true instantly.
<?php while(the_repeater_field('team_members','options') && in_array(get_sub_field('member_sort'),array(1,2,3,4))): ?>
<div class="one_fourth">
<img src="<?php the_sub_field('image'); ?>" alt="" />
<p>
<?php the_sub_field('info'); ?>
<br />
<a href="mailto:<?php the_sub_field('email'); ?>"><?php the_sub_field('email'); ?></a>
</p>
</div>
<?php endwhile; ?>
or, even:
OK, this question has evolved quite a bit but I think the problem is now that you want to loop over all values but only do stuff on certain conditions. You can use the
continuestatement to abort the current iteration and move on to the next immediately.