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 6642545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:56:37+00:00 2026-05-25T23:56:37+00:00

im not sure this is a good question to post but here is my

  • 0

im not sure this is a good question to post but here is my issue. I have an if statement that is getting way too long and i was wondering if there is some other kind of syntax to shorten it out:

if (($time1 <= $one_day)&&
    ($time2 <= $one_day)&&
    ($time3 <= $one_day)&&
    ($time4 <= $one_day)&&
    ($time5 <= $one_day)&&
    ($time1 != NULL)&&
    ($time2 != NULL)&&
    ($time3 != NULL)&&
    ($time4 != NULL)&&
    ($time5 != NULL)){
    //do sometihng
}

this is one example but i have a similar one that goes up to ..&&($time15 <= $one_day).

the statement is pretty self explanatory, $time1, $time2, etc can come back empty so i have to check if they are NULL or not

any ideas?

thanks

  • 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-05-25T23:56:38+00:00Added an answer on May 25, 2026 at 11:56 pm

    You can put the common stuff in a function:

    function validate_time($time, $one_day) {
        return $time <= $one_day && $time != NULL;
    }
    if (validate_time($time1, $one_day) &&
        validate_time($time2, $one_day) &&
        validate_time($time3, $one_day) &&
        validate_time($time4, $one_day) &&
        validate_time($time5, $one_day)) {
        // do something
    }
    

    You may want to refactor code and eliminate the need for copying & pasting those checks. Another way to get the job done:

    while (true) {
        foreach (array($time1, $time2, $time3, $time4, $time5) as $time) {
            if ($time > $one_day || $time == NULL) {
                break 2;
            }
        }
        // do something
        break;
    }
    

    The above could be put in a function as well which would make the while-loop and break keyword redundant. Replace break 2 by return then.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure this question is appropriate here but I hope I could get
Not sure this is a programming question, but we use LaTeX for all our
Not sure this is possible, but looking to write a script that would return
Not entirely sure of a good title for this, feel free to edit it
I'm not sure this is possible, but in ruby, you can dynamically call a
I'm not sure this is possible, but is there a syntax to be used
I'm still not sure this is the correct way to go about this, maybe
I'm sure this is a fairly trivial problem, but I'm not sure what to
Ok I'm working on getting better with python, so I'm not sure this is
This question is similar to this other post , but I'm new to iPhone

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.