Q:

Write a PHP function to test whether a number is greater than 30, 20 or 10 using ternary operator

belongs to collection: PHP basic programs with examples

0

Write a PHP function to test whether a number is greater than 30, 20 or 10 using ternary operator

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following excercise..

<?php
function trinary_Test($n){
$r = $n > 30
? "greater than 30 <br>"
: ($n > 20
? "greater than 20<br>"
: ($n >10
? "greater than 10<br>"
: "Input a number atleast greater than 10!")); 
echo $n." : ".$r."\n";
}
trinary_Test(32);
trinary_Test(21);
trinary_Test(12);
trinary_Test(4);
?>

Result:

32 : greater than 30 
21 : greater than 20
12 : greater than 10
4 : Input a number atleast greater than 10!

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a PHP program to swap two variables... >>
<< Write a PHP script to display string, values withi...