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..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. <?php
  2. function trinary_Test($n){
  3. $r = $n > 30
  4. ? "greater than 30 <br>"
  5. : ($n > 20
  6. ? "greater than 20<br>"
  7. : ($n >10
  8. ? "greater than 10<br>"
  9. : "Input a number atleast greater than 10!"));
  10. echo $n." : ".$r."\n";
  11. }
  12. trinary_Test(32);
  13. trinary_Test(21);
  14. trinary_Test(12);
  15. trinary_Test(4);
  16. ?>

Result

python language techstudy.org

     





Related Topics




Popular Posts