About ternary operator (code with? (Hatena) in if statement) in PHP

Aug 28, 2020 PHP Beginner Programming Study Diary

#Programming study diary August 28, 2020 Summarize expressions with : after ? (Hatena mark). ? and : are ternary operators (conditional operators) that can describe conditional branching expressions. Two symbols are used, but one operator is used.

#How to write In the ternary operator, take three operands that are the target of the operation and write ? and : as follows.

(Conditional expression)? <true expression>: <false expression>
$num = 13;
echo ($num%2==0) ?'true':'false';

// the same as below
if ($num%2==0) {
   echo'true';
} else {
   echo'false';
}

What is the #?? mark (extra edition) ``?` is called null coalescing operator. You can check if this is null.

References

[PHP]? (Hatena mark) and: (colon) conditional operator | Describe conditional branch in one line Ternary operator (How to read “? (Hatena)” in if sentence) [PHP]? ? What is (two question marks)…?