How to abbreviate if in PHP

Source: Internet
Author: User
This article mainly introduces in PHP how to abbreviate if judgment, has a certain reference value, now share to everyone, the need for friends can refer to

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;

3, | |

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;

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.