All that being said, if this is some sort of assignment that specifically wants you to "create a function which accepts two numbers and a symbol", I guess this does not answer that, as you have created 4 separate functions. In that case, you probably want that switch
(or something similar) within the target function, which would accept the operation as a third parameter, something like:
function arithmetic(int|float $a, int|float $b, string $operation): int|float {
switch(strtolower($operation)) {
case 'add':
return $a + $b;
break;
case 'subtract':
return $a - $b;
break;
case 'multiply':
return $a * $b;
break;
case 'divide':
if($b == 0) { throw new Exception("Division by zero not allowed"); }
return $a / $b;
break;
default:
throw new Exception("Invalid operation '$operation'");
}
}
$tests = [[1, 2], [4.5, 3.2], [0,99.999], [-99, 0.0], [5, 10]];
$ops = ['add', 'subtract', 'multiply', 'divide'];
try {
foreach($tests as [$a, $b]) {
foreach($ops as $op) {
echo "$a $op $b = " . arithmetic($a, $b, $op) . "\n";
}
}
} catch(Exception $e) {
echo $e->getMessage()."\n";
}