Write a PHP script to select first 6 words from the following string

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

Introduction

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

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

Add a Comment

Your email address will not be published. Required fields are marked *