I have different 'spots' inside multiple arrays against each city name. Like Houston has two arrays each with a different 'spots' value. What I want to do is add those two 'spots' values against Houston or any cities name, inside maybe a new array. So that when I want to access 'spots' I get the total of 'spots' of a single city.
This is the code inside the controller:
foreach ($request->city as $city) {
$citySpots[$city] = Controller::select('spots')
->where('city', $city)
->get()
->toArray();
}
dd($citySpots);
dd value:
array:2 [▼
"Houston" => array:2 [▼
0 => array:1 [▼
"spots" => "20"
]
1 => array:1 [▼
"spots" => "10"
]
]
"New York" => array:1 [▼
0 => array:1 [▼
"spots" => "500"
]
]
]