New PHP notation

Source: Internet
Author: User

From PHP 5.3, the middle part of the ternary operator can be omitted. Expression expr1?: Expr3 returns EXPR1 when EXPR1 evaluates to TRUE, otherwise returns EXPR3.

<?PHP$test= ' Rookie Tutorial ';//General Wording$username=isset($test) ?$test: ' Nobody ';Echo $username,Php_eol;//PHP 5.3+ version notation$username=$test?: ' Nobody ';Echo $username,Php_eol;?>

Note: Php_eol is a newline character that is compatible with larger platforms.

A NULL merge operator was added to the php7+ version, with the following example:

<? PHP // if $_get[' user '] does not exist return ' nobody ', return the value of $_get[' user '] $username $_get [' User ']?? ' Nobody '; // a similar ternary operator $username isset ($_get$_get[' User ']: ' Nobody ';? >
Combination Comparer (php7+)

php7+ supports combined comparators, as follows:

<?PHP//Integral typeEcho1 <=> 1;//0Echo1 <=> 2;//-1Echo2 <=> 1;//1//floating point typeEcho1.5 <=> 1.5;//0Echo1.5 <=> 2.5;//-1Echo2.5 <=> 1.5;//1//StringEcho"A" <=> "a";//0Echo"A" <=> "B";//-1Echo"B" <=> "a";//1?>

New PHP notation

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.