PHP shorthand expression,&& or | | Abbreviation CONDITION statement

Source: Internet
Author: User

Sometimes I learn a lot, a lot of small details are forgotten, such as simple expression,

Three-dimensional expression?:;

$aa an OR $BB expression

Wait a minute!

Write some simple expressions, Memo!

php && | | Abbreviation CONDITION statement

Look at the following notation:

<? PHP! $var $var = ' Hello! '; $error  die (' error! ');? >

&& is the simultaneous true operator.
A && B, this is true only if both A and B are true.
PHP will first determine if a is true, and if A is true, it will continue to judge B.
So, when a is true and B is a statement, B runs.
Similarly, when a is false, this sentence must be false, there is no need to judge the future, at this time, B will not run.

|| Or is different
A or B, as long as there is one in a or B is true, this sentence is true
PHP first to determine whether a is true, if a is true, this sentence must be true, there is no need to judge B
So when a is false, PHP will continue to judge whether B is true, to get the result of this sentence
This is, B, if it is a statement, it will run.

Remember that data connection at the beginning of the entry? It should be understood now, why add an OR?

[PHP] mysql_connect ($host,$user,$pwddie ('Mysql error!'); [/php]


If the connection fails, the front is false, the back die will run!

Let's look at the following example:

[PHP] $var = ";! $var Echo "It's empty!" ";! $var Print "It's empty!" "; [/php]

which can be executed successfully?

You know why?

Here is the difference between echo and print:

The difference between Echo and print

The functions of ECHO and print are basically the same in PHP, but there are subtle differences between the two. In PHP code, print can be used as a normal function, for example, after executing the following code, the value of the variable $res will be 1.

1 <li>ret = print \ "Hello World \"; </li>

This means that print can be used in some complex expressions, while Echo is not. Similarly, the Echo statement runs slightly faster than the print statement in the code, because the Echo statement does not require any values to be returned.

PHP shorthand expression,&& or | | Abbreviation CONDITION statement

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.