0

I have been staring at this for an hour now. It says I have an Parse error: syntax error, unexpected '{' in line 9.

Could someone please look at this for me. Thanks in advance.

<?php

if(isset($_POST['submit']))
{
 function foo($a, $b)
{
   foreach(array_keys($a) as $i)
   {
      if(array_key_exists($i, $b){
          $result[$i] = $a[$i]*$b[$i];
      }else{
          $result[$i] = 0;
      }
   }
   foreach(array_keys($b) as $i)
   {
      if(not array_key_exists($i, $a){ //exists in b but not i a
          $result[$i] = 0;
      }
   }
   return $result
}
}

?>

3 Answers 3

6

You didn't close your parenthesis correctly:

if(array_key_exists($i, $b){

should be

if(array_key_exists($i, $b)){
2

You are missing an ) on this line:

if(array_key_exists($i, $b){

should be:

if(array_key_exists($i, $b)){
2

Your missing a parenthesis in your first if:

if(array_key_exists($i, $b){

should be

if(array_key_exists($i, $b)){

Also, not is not valid operator (and a parenthesis is also missing). So

if(not array_key_exists($i, $a){

should be

if(! array_key_exists($i, $a)){

And finally you're missing a ; in your return statement:

return $result;

I would advise you to use a PHP IDE such as Eclipse, which will point you syntax errors. We all do mistakes and finding a missing parenthesis in a text only editor can be very frustrating.

Not the answer you're looking for? Browse other questions tagged or ask your own question.