Why does not this code work? [closed]

-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

    
asked by anonymous 20.07.2017 / 21:51

2 answers

6

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;
}
    
20.07.2017 / 21:52
1

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.

    
20.07.2017 / 21:52