Hướng dẫn dùng ternary complex trong PHP
The code will be executed front to back. So first Show
will result in Then the next questionmark will result in Also because of the above it would be good to notice that The solution would be something like:
* Edit: * Thank you for the upvotes. When looking again at this I got lost in my own post, because the logic is so complex. So for others reading this: The logic the OP posted can be simplified to the following:
The OP would expect this to result in Comparison operators, as their name implies, allow you to compare two values. You may also be interested in viewing the type comparison tables, as they show examples of various type related comparisons. Comparison Operators
If both operands are numeric strings, or one operand is a number and the other one is a numeric string, then the comparison is done numerically. These rules also apply to the switch statement. The type conversion does not take place when the comparison is Warning Prior to PHP 8.0.0, if a string is compared to a number or a numeric string then the string was converted to a number before performing the comparison. This can lead to surprising results as can be seen with the following example:
"a") { Output of the above example in PHP 7: bool(true) bool(true) bool(true) bool(true) 0 Output of the above example in PHP 8: bool(false) bool(true) bool(true) bool(true) a
echo 1.5 <=> 1.5; // 0 For various types, comparison is done according to the following table (in order). Comparison with Various Types
Example #1 Boolean/null comparison
Example #2 Transcription of standard array comparison
Warning Comparison of floating point numbersBecause of the way floats are represented internally, you should not test two floats for equality. See the documentation for float for more information.
Incomparable Values While identity
comparison ( Ternary OperatorAnother conditional operator is the "?:" (or ternary) operator. Example #3 Assigning a default value
The expression It is possible to leave out the middle part of the ternary operator. Expression
Null Coalescing OperatorAnother useful shorthand operator is the "??" (or null coalescing) operator. Example #6 Assigning a default value
The expression In particular, this operator does not emit a notice or warning if the left-hand side value does not exist, just like isset(). This is especially useful on array keys.
crazy888s at hotmail dot com ¶ 12 years ago
niall at maranelda dot org ¶ 4 years ago
adam at caucho dot com ¶ 16 years ago
rshawiii at yahoo dot com ¶ 16 years ago
count($a1) == count($a2))
bishop ¶ 15 years ago
Sumon Mahmud ¶ 2 years ago
Cuong Huy To ¶ 11 years ago
Ryan Mott ¶ 2 years ago
Marcin Kuzawiski ¶ 7 years ago
admin at zeros dot co dot id ¶ 1 month ago
Tahazzot ¶ 1 year ago
|