Conditional statements written in && PHP-three conditional statements

Source: Internet
Author: User
First type: IF condition statement

The second type: three mesh operation

The third kind of:&&, | | Conditional statements made up of

The first kind: IF do not say, this is the foundation, I believe most people will;

The second kind: C=a>b? True:false//means: If the a>b is true then return true, otherwise return false (of course, can be replaced with a statement), and return the result to C;

The third type:

1. &&

In most languages, he means and meaning, that is, the left and right sides are true, using PHP as an example, traditionally used;

if ($a >0 && $b >0) {      //statement;}

Execute the statement when both are true;

Today, however, we use him as a conditional statement, for example there is a traditional conditional statement at the bottom:

if ($a >0) {

$b = ' This is test ';

}

The statement is executed when the condition is true, but it is too cumbersome to write, so we can write it directly:

$a >0 && ($b = ' This is test ');

The computer will first determine whether a $ A is true, if it is, then execute the following statement, if no, the subsequent statement will not be necessary to execute;

Benefits: 1, can be written in one line,

2, omit the code;

2, | |

Unexpectedly && can write conditional statements like this, then | | Of course, it is possible, but his order of execution is not the same.

$a >0 | | ($b = ' This is test ');

The computer first determines whether a $ A >0 is true, is: The following statement will not execute, no: execute;


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the use of && PHP written conditional statements-three conditional statements, including aspects of the content, I hope to be interested in the PHP tutorial friends helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.