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

  • SEARCH
  • Home
  • 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 321583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:51:32+00:00 2026-05-12T08:51:32+00:00

How does PHP read if statements? I have the following if statements in this

  • 0

How does PHP read if statements?

I have the following if statements in this order

if ( $number_of_figures_in_email < 6) {
       -- cut: gives false
}


if($number_of_emails > 0) {                                                                         
      -- cut: gives false
} 

if ( $number_of_emails == 0) {
   -- cut: gives true
}

The code behaves randomly. It sometimes goes to the third if clause and gives me a success, while sometimes to the one of the first two if clauses when the input variables are constant.

This suggests me that I cannot code only with if statements.

  • 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-12T08:51:33+00:00Added an answer on May 12, 2026 at 8:51 am

    It doesn’t “behave randomly”, it does what you tell it to do:

    if ($a) {
        // do A
    }
    
    if ($b) {
        // do B
    }
    
    if ($c) {
        // do C
    }
    

    All three ifs are independent of each other. If $a, $b and $c are all true, it’ll do A, B and C. If only $a and $c are true, it’ll do A and C, and so on.

    If you’re looking for more “interdependent” conditions, use if..else or nested ifs:

    if ($a) {
        // do A and nothing else
    } else if ($b) {
        // do B and nothing else (if $a was false)
    } else if ($c) {
        // do C and nothing else (if $a and $b were false)
    } else {
        // do D and nothing else (if $a, $b and $c were false)
    }
    

    In the above only one action will get executed.

    if ($a) {
        // do A and stop
    } else {
        // $a was false
        if ($b) {
            // do B
        }
        if ($c) {
            // do C
        }
    }
    

    In the above both B and C might get done, but only if $a is false.

    This, BTW, is pretty universal and not at all PHP specific.

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

Sidebar

Related Questions

any time i write this: $this->setTemplate('module/action'); I'm getting this error: The template module/actionSuccess.php does
I have set my cookie in PHP using the following: setcookie(id, 100, time()+100000, /AP,
I have a web application using PHP and PDO with SQLSRV prepared statements to
Please read the code below: <?php $flag = 1; $name = $_GET['name']; if($name ==
I have been spotting the sentence PHP PDO's prepared statements prevents SQL injection .
I'm not sure what is happening. I have this code: `case (XMLREADER::ELEMENT): $node_type =
I want to have PHP read an (uploaded) powerpoint presentation, and minimally extract the
The php code is supposed to read the shared memory I create in a
Read Carefully The question here is not that does PHP parser processes comments or
Does PHP expose Apache's Mime-Type to extension mapping in any way shape or form.

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.