What else is the meaning of PHP IF else simplified/ternary one-time use

Source: Internet
Author: User
In general we will write this:

Copy the Code code as follows:


if ($_get[' time ']==null)
{
$time = time ();
}
Else
{
$time = $_get[' time '];
}
Echo $time;
If get has time this value is brought into the variable.
?>


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:

Copy the Code code as follows:


$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 ()

Copy the Code code as follows:


$a = 5; Defining Variables A=5
$b = 3; Defining Variables B=5
$c = ($a = = $b)? ("Yes"): ("no");
If A=b,c is =yes; A is not equal to B,c =no
?>


There is also a simplified

Copy the Code code as follows:


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


can be simplified into

Copy the Code code as follows:


$bool && Setvaluefun ();

The above describes what else is the meaning of the PHP IF else simplification/ternary one-time use, including what else is the meaning of the content, I hope to be interested in 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.