Good evening. Tell me, please, how to do it. There is an array: $ prods

Array ( [21020] => 1050 [19671] => 1000 ) 

And cycle

 $basketItem->setFields(array( 'PRODUCT_ID' => '', 'CUSTOM_PRICE' => 'Y', 'PRICE' => '', )); 

I can not understand how to transfer values ​​from an array to $ basketItem.

Where PRODUCT_ID is 17215 and 21020 and PRICE is 3200 and 1050, respectively.

  • And where is the cycle itself? And what action do you expect? What are you working with, what is the expected result? - Nikolaj Sarry
  • foreach($prods as $k=>$v)$basketItem->setFields(['PRODUCT_ID'=>$k, 'PRICE'=>$v]); - vp_arth

1 answer 1

 PRODUCT_ID => array_keys($prod) 

And for the second parameter

 PRICE => array_values($prod) 

Write the key arrays (0 => 17215, etc.) and values ​​(0 => 3200, etc.) into these parameters

Accordingly, to get the values, you will write (when you receive this array) $array['PRODUCT_ID'][$i] in a loop. And the second value will also be selected.