I have this code:
function multiply(a, b) {
return a * b
}
I wonder why it does not work?
Error returned:
PHP Parse error: syntax error, unexpected ',', expecting variable (T_VARIABLE) in /home/codewarrior/run.php on line 5
I have this code:
function multiply(a, b) {
return a * b
}
I wonder why it does not work?
Error returned:
PHP Parse error: syntax error, unexpected ',', expecting variable (T_VARIABLE) in /home/codewarrior/run.php on line 5
I believe you have taken the code from here .
What happens is that you're missing some basic things like using $
to indicate variables passed as parameters:
Variables in PHP are represented by a dollar sign ($) followed by the variable name. 1
And it's also missing% com_point (semicolon) at the end of the second line of your program:
PHP requires that statements be terminated with a semicolon at the end of each command. 1
Finally, you can use your code in this way:
function multiply($a, $b) {
return $a * $b;
}
Because you forgot to put ;
at the end of the line.
function multiply($a, $b) {
return $a * $b;
}
Initially I thought the problem was in JavaScript because its variables were without the $
needed for PHP to recognize as a variable, but actually its function is in PHP as follows the tag, so I believe you have confused and was programming JavaScript in PHP. (I've been there)
So keep in mind that to declare and use variables in PHP you have to use $
at the beginning of each of them.