This is what the array $optvar looks like in response
0: [{product_id: 18, option_id: 35, value: "green"}, {product_id: 18, option_id: 36, value: "large"}]
1: [{product_id: 18, option_id: 35, value: "green"}, {product_id: 18, option_id: 36, value: "large"}]
I want to add sk_id: $somevalue in each of the inner array;
I tried using foreach loop but only getting the last item when I call it outside the loop;
my loop:
foreach ($optvar as $innerArray) {
if (is_array($innerArray)){
foreach ($innerArray as $k => &$value) {
if($value['option_id'] == $option)
{
$value['option_id'] =$var[$key]['value'];
}
$value['sku_id'] = $sku->id;
$value['created_at'] = $now;
$value['updated_at'] = $now;
}
}
}