Generally we will write like this:
Copy code The code is as follows:
if($_GET[' time']==null)
{
$time = time();
}
else
{
$time = $_GET['time'];
}
echo $time;
//If GET has the value of time, bring in the variable time, if not, bring the current time() time
?>
If Just a simple judgment, writing as above is too troublesome, and the efficiency is not high!
You can change it to use a three-dimensional linear expression:
Copy code The code is as follows:
$time = ($_GET['time']==null) ? (time()) : ($_GET['time' ]);
echo $time;
?>
Much simpler!
Briefly explain the meaning of ternary one-time expression
If the first bracket () If the judgment sentence is true, execute the content of the first bracket () after the question mark?. If it is not true, execute the content of the second bracket () after the question mark?
Copy code The code is as follows:
$a = 5; //Define variable a=5
$b = 3; //Define variable b=5
$c = ($a==$b) ? ("yes") : ("no");
//If a=b, c=yes; a is not equal to b, c=no
?>
There is also a simplification
Copy the code The code is as follows:
$bool = true;
if($bool)
{
setValueFun();
}
can be simplified to
Copy code The code is as follows:
$bool && setValueFun();
http://www.bkjia.com/PHPjc/324135.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324135.htmlTechArticleGenerally we will write like this: Copy the code The code is as follows: ? if($_GET['time']==null ) { $time = time(); } else { $time = $_GET['time']; } echo $time; //If GET has the value of time, bring in the variable...