foreach($data['sku'] as $key=>$val) {
$attribute = new ProductsAttributes;
$attribute->product_id = $id;
$attribute->sku = $val;
$attribute->size = $data['size'][$key];
$attribute->price = $data['price'][$key];
$attribute->stock = $data['stock'][$key];
$attribute->save();
}
I don't understand this code because of $data['size'][$key].
Why do I have to use $key instead of $val ?
If I use $val, it throws an array to string conversion error