Write a example code showing the nested ternary conditional operator in PHP?

Last updated 5 years, 7 months ago | 3322 views 75     5

Tags:- PHP

PHP | Nested ternary conditional operator

An example code showing the nested ternary conditional operator in PHP.

<?php

$background_color = ($num == 0 ? 'blue' : ($num > 0 ? 'green' : 'red'));

?>

Here we are assigning different strings to the $background_color variable based on a numeric value ($num).