PHP IF Else simplified/ternary one-time use

Source: Internet
Author: User

Tag: equals to explain set meaning a performance and define fun

In general we will write this:

if ($_get[' time ']==null$timetimeelse$ time$_get[' Time 'echo$time//

If only simple judgment, according to the above writing is too troublesome, and the performance is not high!
Can be changed to use ternary one-time:

$time = ($_get[' time ']==null)? (Time ()): ($_get[' Time 'echo$time

Much more concise!
Probably explain the meaning of ternary one-time
If the sentence inside the first parenthesis () is set, the question mark is executed? The contents of the first parenthesis (), if not, execute the question mark? The contents of the second parenthesis ()

$a //  $b//$c = ($a= =$b)? ("Yes"): ("No"//

There is also a simplified

$bool = true;
if ($bool)
{
Setvaluefun ();
}

can be simplified into

$bool && setvaluefun ();

PHP IF Else simplified/ternary one-time use

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.