php syntax error on line 9
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
}
}
?>
You didn't close your parenthesis correctly:
if(array_key_exists($i, $b){
should be
if(array_key_exists($i, $b)){
 You are missing an ) on this line:  
if(array_key_exists($i, $b){
should be:
if(array_key_exists($i, $b)){
 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.
链接地址: http://www.djcxy.com/p/11996.html上一篇: 解析错误:语法错误,意外的'{',期待'('帮助?
下一篇: 第9行的php语法错误
