In: Computer Science
When $type is 'VIP', set $rate at 0.20. When $type is not 'VIP' and if $quantity is greater than or equal to 10, set $rate to 0.1; otherwise, set $rate to 0.0. Assume that the values for $type and $quantity are known. in the following write just one PHP if statement (not several separate if statements) to cover the above situations.
Dear Student ,
As per requirement submitted above kindly find below solution.
Question :
Answer :
$rate=($type=="VIP")?$rate=0.20:(($type!="VIP" && $quantity>=10)?$rate=0.1:$rate=0.0);
Explanation :
Demonstration :
<?php
//declaring variables
$type="sVIP";
$quantity=20;
//using ternary operator
$rate=($type=="VIP")?$rate=0.20:(($type!="VIP" && $quantity>=10)?$rate=0.1:$rate=0.0);
//print value of $rate
echo "rate :".$rate;
?>
==================================
Screen when $type =VIP :
Screen when $type =sVIP and qunatity is less than 10 :
Screen when $type =sVIP and qunatity is greater than 10 :
NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.