Home > Backend Development > PHP Tutorial > Code examples of two ways to write PHP ternary operations_PHP tutorial

Code examples of two ways to write PHP ternary operations_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:29:53
Original
914 people have browsed it


First, let’s look at a simple example now:

Copy the code The code is as follows:
$a = 2;
($a == 1) ? $test = "Enterprise" : $test = "Region";#Writing method 1
echo $test;
?>

In the above example, first determine whether $a is 1. If the string "enterprise" is stored in the $test variable and then output, if not the string "region" is stored in the $test variable and then output. ;
The appeal example code is equivalent to:
Copy code The code is as follows:
$a = 2;

#Writing method 2
$test = ($a == 1) ? "Enterprise" : "Region";

#Writing method three
if($a == 1){
$test="enterprise";
}else{
$test="region";
}
echo $test;

?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/769238.htmlTechArticleFirst, let’s look at a simple example now: Copy the code as follows: ?php $a = 2; ($ a == 1) ? $test = "Enterprise" : $test = "Region";#Writing method 1 echo $test; ? As for the above example, first...
Related labels:
php
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template