Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created August 20, 2020 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/8775b48efcfb934c7b18dfd1ee5ed56b to your computer and use it in GitHub Desktop.
Save phpfiddle/8775b48efcfb934c7b18dfd1ee5ed56b to your computer and use it in GitHub Desktop.
[ Posted by Majid ] Updated the php code
<?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