Home > Backend Development > PHP Tutorial > What does else mean? PHP IF ELSE simplification/use of three-dimensional one-time formula

What does else mean? PHP IF ELSE simplification/use of three-dimensional one-time formula

WBOY
Release: 2016-07-29 08:46:37
Original
1338 people have browsed it

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 you only make a simple judgment, it would be too troublesome to write as above, and the efficiency is not high!
You can change it to use a three-dimensional linear expression:

Copy the code The code is as follows:


< ;?
$time = ($_GET['time']==null) ? (time()) : ($_GET['time']);
echo $time;
?>


Much simpler!
Explain roughly the meaning of the ternary formula
If the judgment sentence in the first bracket () is true, execute the content of the first bracket () after question mark?, if it is not true, execute the content of the second bracket () after question mark? Content

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 another A kind of simplification

Copy code The code is as follows:


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


can be simplified to

Copy code The code is as follows:


$bool && setValueFun();

The above introduces what else means. PHP IF ELSE simplifies/the use of ternary one-time formula, including what else means. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template