Created
August 20, 2020 11:20
-
-
Save phpfiddle/8775b48efcfb934c7b18dfd1ee5ed56b to your computer and use it in GitHub Desktop.
[ Posted by Majid ] Updated the php code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$x=5; | |
$y=6; | |
$a=1; | |
switch ($a) { | |
case '1': | |
sum($x,$y); | |
break; | |
case '2': | |
minus($x,$y); | |
break; | |
case '3': | |
multiply($x,$y); | |
break; | |
case '4': | |
divide($x,$y); | |
break; | |
default: | |
echo"invalid number using switch()"; | |
break; | |
} | |
function sum($x,$y){ | |
$sum=$x+$y; | |
echo " this is sum value using Switch() =$sum"; | |
} | |
function minus($x,$y){ | |
$minus=$x-$y; | |
echo " this is minus vlaue using Switch() =$minus"; | |
} | |
function multiply($x,$y){ | |
$multiply=$x*$y; | |
echo " This is multiply value using Switch() =$multiply"; | |
} | |
function divide($x,$y){ | |
$divide=$x/$y; | |
echo " this is divide value using Switch()=$divide"; | |
} | |
?> | |
<br/> | |
<?php | |
$n=5; | |
$z=6; | |
$p=1; | |
if($p==1){ | |
sum_f($n,$z); | |
} | |
elseif($p==2){ | |
minus_f($n,$z); | |
} | |
elseif($p==3){ | |
multiply_f($n,$z); | |
} | |
elseif($p==4){ | |
divide_f($n,$z); | |
} | |
else | |
{ | |
echo "Sorry invalid number using If-else condition"; | |
} | |
function sum_f($n,$z){ | |
$sum=$n+$z; | |
echo " this is sum value using If-else condition =$sum"; | |
} | |
function minus_f($n,$z){ | |
$minus=$n-$z; | |
echo "this is minus value using If-else condition =$minus"; | |
} | |
function multiply_f($n,$z){ | |
$multiply=$n*$z; | |
echo " this is multiply value using If-else condition=$multiply"; | |
} | |
function divide_f($n,$z){ | |
$divide=$n/$z; | |
echo " this is divide value using If-else condition=$divide"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment