Home > Backend Development > PHP Tutorial > PHP ternary operation_PHP tutorial

PHP ternary operation_PHP tutorial

WBOY
Release: 2016-07-15 13:21:50
Original
1115 people have browsed it

$a = 2;

$a == 1 ? $test="Enterprise" : ($a==2 ? $test="Region" : $test="Other places");
echo $test;
First determine whether $a is 1. If it is, output the enterprise directly. If not, continue to judge, which is equivalent to nesting an if inside else. If it is equal to 2, output the region. If it is not, output elsewhere
is equivalent to
$a = 2;
if($a == 1) {
echo $test="Enterprise";
} else {
if($a == 2){
$test = "Region";
} else {
$test="Elsewhere";
}
}
echo $test;
or
if($a == 1) {
echo $test="Enterprise";
} else {
$a==2 ? $test="region" : $test="other places";
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477119.htmlTechArticle$a = 2; $a == 1 ? $test=Enterprise: ($a==2 ? $ test=region: $test=other places); echo $test; first determine whether $a is 1. If it is to output the enterprise directly, if not, continue to determine the equivalent of el...
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