I have an array in laravel named $destinations and the values are:
Collection {#391 ▼
#items: array:2 [▼
"Chicago, Illinois" => Collection {#398 ▼
#items: array:10 [▶]
}
"New York City, New York" => Collection {#403 ▼
#items: array:10 [▶]
}
]
}
This array is grouped by city name just like Chicago and New York, now I want to add one array item after the city name, it should be like this:
Collection {#391 ▼
#items: array:2 [▼
"Chicago, Illinois" => Collection {#398 ▼
#items: array:10 [▶]
"days" => "2"
}
"New York City, New York" => Collection {#403 ▼
#items: array:10 [▶]
"days" => "7"
}
]
}
I'm trying to use array_merge when i loop the array, I use foreach($destinations as $key => $destination) in the looping, basically the $key will return increment number like 0, 1, 2, etc but in this case it return the city name. Anyone knows how to do it? or how to make the $key still increment number after grouped by in laravel?