I'm trying to make a calculator in PHP now I have written a function in php to add few numbers but its concatenate instead of adding it can someone please help me guide me to do the task.
function cal($val1 , $opt , $val2){
return $sum = $val1 . $opt . $val2;
}
Now, if I'm calling this function like:
echo cal(4,"+",5);
It returns 4+5
but I'm looking 9
for an answer
can it be possible that $opt works as an operator instead of a string and i can add or subtract based on operators like