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
    }
    }
    
    ?>

