今天一个网友在群里发了个题目不难,但是可能会错
echo
$a == 1 ? 'one' :
$a == 2 ? 'two' :
$a == 3 ? 'three' :
$a == 4 ? 'foura' : 'other';
echo "\n";
输出结果是:
结果是:four
一开始想不明白,按照我的理解,应该是这样的逻辑:
echo ($a == 1 ? 'one' :
( $a == 2 ? 'two' :
( $a == 3 ? 'three' :
($a == 4 ? 'four' : 'other'))));
输出为:two
后来在kevinG(qq:48474)的指教下,参看php手册,终于明白了php的三元符的解释是从左到右的,
Statement: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