Introduction to the use of php ternary operators, php operators. Introduction to the use of php ternary operators. when we write php operators, if {...} else {...} most of them are used, but sometimes we can use the ternary operation in C to introduce the use of the php ternary operator and the php operator.
When we write PHP, it is possible that if {...} else {...} most of them are used, but sometimes we can use the ternary operation in C to reduce the code! This article describes some tips and notes for using ternary computation in php development. For more information about the coders, see.
Today, a netizen posted a question in the group, but it may be wrong.
echo $a == 1 ? 'one' : $a == 2 ? 'two' : $a == 3 ? 'three' : $a == 4 ? 'foura' : 'other'; echo "\n";
The output result is:
Result: four
I cannot understand it at first. according to my understanding, the logic is as follows:
Echo ($ a = 1? 'One ':
($ A = 2? 'Two ':
($ A = 3? 'Three ':
($ A = 4? 'Four': 'Other '))));
Output: two
Later, with the help of kevinG (qq: 48474), I read the php manual and finally understood that the interpretation of the php trielement was from left to right,