I want to update an array inside foreach I tried this two code :
code 1 :
foreach ($listOrders as $k => $order) {
foreach ($listOrders as $key => $o)
{
if ($o["id_order"] == $order["id_order"])
{
unset($listOrders[$key]);
}
}
in this codeunset is not working
code 2 :
foreach ($listOrders as $k => &$order) {
foreach ($listOrders as $key => $o)
{
if ($o["id_order"] == $order["id_order"])
{
unset($listOrders[$key]);
}
}
If I use & with $order $listOrders will not returned all data that I want.
Your error should be here
Remove &
Also you are iterating through your $listOrders twice with your code, won't your array list always be empty after the iteration is finished?