I’ve array like this in php I want to loop this array inside div elements in php:
`Array
(
[item] => Array
(
[0] => Masaladosa
[1] => Zingafry
[2] => Idli
[3] => Tandoori Baby Corn Mushroom
[4] => Bharwan Aloo
)
[qty] => Array
(
[0] => 2
[1] => 4
[2] => 2
[3] => 2
[4] => 2
)
[price] => Array
(
[0] => 320
[1] => 800
[2] => 70
[3] => 560
[4] => 560
)
)`
I want to use loop this array inside following div:
<div class="row mt-4 mx-1">
<div class="col-6 text-start item-listmenu">
<p class="bill-order">Masala dosa</p>
</div>
<div class="col-2 text-start">
<p class="bill-order">2</p>
</div>
<div class="col-4 text-end">
<p class="bill-order"><span>₹</span>320</p>
</div>
</div>
and so on.
2
Answers
The easiest solution: Split the array into three (one for Item, Qty, and Price), and use a foreach with a named index variable. This works as long as the numerical index is consistent across all three nested arrays:
I know this isn’t an answer per se but I don’t know how in a comment to write the layout of the array.
And so, all that to say that the organization of your data in arrays is very strange.
Can’t you have a array of this type instead…?
It would be much more consistent and easier to navigate to view the layers.
…