How to add multi dimensional array value multiple times to same object?

29 Views Asked by At

The code snippet is as below:

$test = new PartnerRestrictionTransfer();
foreach($data as $data2)
{
  
  $data =  $test->setProductSku($data2);
}
print_r($data);die;
1

There are 1 best solutions below

0
B-shan On BEST ANSWER

You require to create new object every-time you get new value for $data2 variable. Also for readability you can use different name for your object variable.

Below is the updated code:

foreach($data as $data2)
{
  $test = new PartnerRestrictionTransfer();
  $var[data1] =  $test->setProductSku($data2);
}
print_r($var);die;