<?php
// define a function for calculation
function calculate($val1,$val2,$opr) {
if($opr=='add'){
return $val1+$val2; // return value
}
if($opr=='sub'){
return $val1-$val2; // return value
}
if($opr=='mul'){
return $val1*$val2; // return value
}
}
//call a function where first two parameters values and other mention operation you need to perform
$result = calculate(2,5,'mul'); //multiply operation
echo $result;
//print output 10
?>
No comments:
Post a Comment