Hi I have a collection of array which I get from a foreach loop. It has no index and I want to modify it.
$productsRange = ProductPricesInventoryTax::where('sale_price', '>=', $min_price)
->where('sale_price', '<=', $max_price)
->get();
foreach($productsRange as $product){
$products = Product::where('id', '=', $product->product_id)->paginate(15);
$productDetails = $this->prepareAllProductDetails($products);
$array = $productDetails[0];//this returns the unidexed array
echo "<pre>";
print_r($array);
the array looks like this.
Array
(
[id] => 1
[sku] => 258
[name] => Bingo Mad Angles Chaat Masti
[is_configurable_product] => 1
[mrp] => 20
[sale_price] => 20
[image] => 258-bingo-mad-angles.jpeg
[brand] => Bingo
[configurable_attributes] => Array
(
[0] => Array
(
[child_product_id] => 2
[name] => Weight
[value] => 90 gms
[mrp] => 20
[sale_price] => 20
)
)
)
Array
(
[id] => 3
[sku] => 262
[name] => India Gate Basmati Rice-Rozana
[is_configurable_product] => 1
[mrp] => 620
[sale_price] => 444
[image] => 262-india-gate.jpeg
[brand] => India Gate
[configurable_attributes] => Array
(
[0] => Array
(
[child_product_id] => 4
[name] => Weight
[value] => 5 Kgs
[mrp] => 620
[sale_price] => 444
)
)
)
But Now I want the array to look something like this which has array index on every array.
Array
(
[0] => Array
(
[id] => 1
[sku] => 258
[name] => Bingo Mad Angles Chaat Masti
[is_configurable_product] => 1
[mrp] => 20
[sale_price] => 20
[image] => 258-bingo-mad-angles.jpeg
[brand] => Bingo
[configurable_attributes] => Array
(
[0] => Array
(
[child_product_id] => 2
[name] => Weight
[value] => 90 gms
[mrp] => 20
[sale_price] => 20
)
)
)
[1] => Array
(
[id] => 3
[sku] => 262
[name] => India Gate Basmati Rice-Rozana
[is_configurable_product] => 1
[mrp] => 620
[sale_price] => 444
[image] => 262-india-gate.jpeg
[brand] => India Gate
[configurable_attributes] => Array
(
[0] => Array
(
[child_product_id] => 4
[name] => Weight
[value] => 5 Kgs
[mrp] => 620
[sale_price] => 444
)
)
)
Please help .