How To Use The PHP Ternary Operator?

Forums PHPHow To Use The PHP Ternary Operator?
Staff asked 2 years ago

How to use the PHP Ternary Operator?

Answers (1)

Add Answer
Karan Rajgor Marked As Accepted
Staff answered 2 years ago

Example: If the value of $a is larger than 25, $30 will be returned and allocated to $b; else, $15 will be returned and assigned to $b.

<?php
  $a = 20;
  $b = $a > 25 ? 30 : 15;
  print ("Value of b is " . $b);
?>

 

Subscribe

Select Categories