PHP Creating a formula from mysql db values and db stored math operator

ok, i managed to get it to work with this

        $amount1 = $invoice_amount;
    $operator = $invoice_operator;
    $amount2 = $invoice_multiplier;
    $rvalue = mcalc ($amount1,$operator,$amount2);
    
    

    function mcalc ($amount1,$operator,$amount2) {
    
        if($operator=="+")
            $result=$amount1+$amount2;
        else if($operator=="-")
            $result=$amount1-$amount2;
        else if($operator=="x")
            $result=$amount1*$amount2;
        else if($operator=="/")
            $result=$amount1/$amount2;

        return $result;
    
    }
    
    echo $rvalue;

error code: 523