What is a ternary, and what ternary operators are available in php 7.4?
What are the advantages and disadvantages of using a ternary?
Here is an example of a set of nested ternaries:
$x = null;
function test(int $x)
{
return $x > 0 ? $x % 2 !== 0 ? $x * 2 : $x / 2 : 0;
}
$y = test($x);What is the value of $y when $x is:
- 5
- '7'
- 10
- 'a'
That code is hard to read, please rewrite the code to be more readable.
$x = null;
function test(int $x)
{
}
$y = test($x);