Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8029189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:21:39+00:00 2026-06-05T00:21:39+00:00

Possible Duplicate: php if statement with multiple conditions I have this code: if(x==1 ||

  • 0

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; ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:21:40+00:00Added an answer on June 5, 2026 at 12:21 am
    if (in_array($x, array(1,2,3,4))
    

    or, even:

    if (in_array($x, range(1, 4)))
    

    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 continue statement to abort the current iteration and move on to the next immediately.

    <?php while (the_repeater_field('team_members','options')) : ?>
        <?php if (!in_array(get_sub_field('member_sort'), array(1,2,3,4))) continue; ?>
    
        ... do stuff
    
     <?php endwhile; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: PHP make if shorter I have an if statement that looks like
Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
Possible Duplicate: PHP: “Notice: Undefined variable” and “Notice: Undefined index” This code shows warnings
Possible Duplicate: php/Mysql query with inserting date fails I have a datepicker code below:
Possible Duplicate: php warning mysql_fetch_assoc I have tried my code and it seems to
Possible Duplicate: Performing simple arithmetic in MySQL statement or in PHP code Im wondering
Possible Duplicate: PHP detecting request type (GET, POST, PUT or DELETE) This should be
Possible Duplicate: PHP ToString() equivalent I get this error: Catchable fatal error: Object of
Possible Duplicate: php == vs === operator Reference - What does this symbol mean
Possible Duplicate: PHP code is not being executed (i can see it on source

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.