PHP Ternary operator

Ternary operator conditional operators are used for executing code if a given statement is true or false. Ternary conditional operators are used to reduce space used by if-else statements.

Ternary Operator(?:)

If the condition is true, then the first statement. Else the second statement is the output.

Syntax:
(Conditional Statement) ? (Return value1) : (Return value2);
			

<?php
  $m = 10;
  echo ($m < 0) ? 'The number is negative' : 'The number is positive';
?>

				

Output:

The number is positive