Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 518 Bytes

File metadata and controls

35 lines (25 loc) · 518 Bytes

Q3

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);