如何使用带有array_key_exists函数的foreach

I am trying to loop around an array of return values from a 'POST form' and to then place those values into a database.

the problem that I have is to determine the best way to loop around those values. I tried using the array_key_exists(). but it appears that this function only works with an If clause.

I am working in ZendFrameWork 1.

I enclose my code below and would really appreciate any help and advice.

 foreach(array_key_exists('id', $ReturnedPostvalues))

     $product = EP3D::getSource('EP3D/Products')->retrieve($productId);
     {  
      $product->quantity = $ReturnedPostvalues['quantity'];
      $product->price = $ReturnedPostvalues['price'];
      $product->rrp = $ReturnedPostvalues['rrp'];

      $product->save();
     }
    }

the var_dumped array values returned from the post

 array(6) {
    ["quantity"]=>
    string(3) "222"
    ["price"]=>
    string(3) "220"
    ["rrp"]=>
    string(2) "22"
    ["sampleId"]=>
    string(5) "42960"
    ["id"]=>
    string(1) "5"
    ["delete"]=>
    string(1) "0"
  }
  [6]=>
  array(7) {
    ["quantity"]=>
    string(4) "7777"
    ["price"]=>
    string(4) "2022"
    ["rrp"]=>
    string(2) "22"
    ["sampleId"]=>
    string(5) "42960"
    ["id"]=>
    string(1) "6"
    ["delete"]=>
    string(1) "0"
  }

I basically need to loop around this array and input the data into the database.

Maybe this is what you want:

foreach($ReturnedPostvalues as $value) {
    if (array_key_exists('id', $value)) {
        $product = EP3D::getSource('EP3D/Products')->retrieve($value['id']);
        $product->quantity = $value['quantity'];
        $product->price = $value['price'];
        $product->rrp = $value['rrp'];

        $product->save();
    }
}

You need to refresh your understanding of multi-dimensional arrays. Your problem is that you seemed to confuse accessing the top-level array and accessing the sub-arrays.