Home > Backend Development > PHP Tutorial > Instructions for using the ternary operator in php_PHP tutorial

Instructions for using the ternary operator in php_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:27:32
Original
925 people have browsed it

Today a netizen posted a question in the group. It is not difficult, but it may be wrong

Copy the code The code is as follows:

echo
$a == 1 ? 'one' :
$a == 2 ? 'two' :
$a == 3 ? 'three' :
$a == 4 ? 'foura ' : 'other';
echo "n";

The output result is:




The result is: four

I didn’t understand it at first, but according to my understanding, the logic should be like this:
echo ($a == 1 ? 'one' :
( $a == 2 ? 'two' :
( $a == 3 ? 'three' :
($a == 4 ? 'four' : 'other'))));
The output is: two

Later in Under the guidance of kevinG (qq:48474), and referring to the PHP manual, I finally understood that the interpretation of PHP's ternary symbols is from left to right,
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