Pergunta

I've got a problem with my code and I'd like to get some help with it.

I've been trying to make a calculator, however this issue has occurred when trying to view the site.

"Parse Error: Syntax Error, unexpected ',' in C:// on line 14" 

Underneath is part of my code, including where the error was indicated.

<?php

function add($num1,$num2,$num3,$num4)
{
    return ($num1,$num2,$num3,$num4); //error 
}

function clear(){
    return 0;
}

?>

The error I received is on line 14 which is where the return line is, which I pointed out in the code.

If you guys could help me out and say whats wrong about my code, why this error occurs and how to fix it, I'd really appreciate it!

If you need too see more code please tell me!

Foi útil?

Solução

For returning a String you've to concat the return variables with dots:

function add($num1,$num2,$num3,$num4) {
    return $num1 . $num2 . $num3 . $num4; 
}

For returning an Integer sum you could sum it this way:

function add($num1,$num2,$num3,$num4) {
    return ($num1 + $num2 + $num3 + $num4); 
}

Returning an Array like this:

function add($num1,$num2,$num3,$num4) {
    return array($num1, $num2, $num3, $num4); 
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top