By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy

Q: Add and Subtract - PHP Function Task

+2 votes

You will receive 3 integers. Write a function sum to get the sum of the first two integers and subtract function that subtracts the third integer from the result from the Sum function.


add and subtract php function task

asked in PHP category by user golearnweb

1 Answer

+1 vote

Here is my answer:


$number1 = intval(readline());
$number2 = intval(readline());
$number3 = intval(readline());
$endResult = addAndSubtract($number1, $number2, $number3);

echo $endResult;

function addAndSubtract($n1, $n2, $n3) {
    $result = 0;
    $result += $n1 + $n2;
    $result -= $n3;
    return $result;
answered by user andrew