Write a PHP function to test whether a number is greater than 30, 20 or 10 using ternary operator.
<?php function trinary_Test($n){ $r = $n > 30 ? "greater than 30" : ($n > 20 ? "greater than 20" : ($n >10 ? "greater than 10" : "Input a number atleast greater than 10!")); echo $n." : ".$r."\n"; } trinary_Test(32); trinary_Test(21); trinary_Test(12); trinary_Test(4); ?>
Sample Output:
32 : greater than 30 21 : greater than 20 12 : greater than 10 4 : Input a number atleast greater than 10!
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer