I try to save records of indexed buildings in my array since I can register 1 or more buildings in a single form, for each building I want to store name_building, number_calls, and prefix_calls. My code is as follows
$edificios = array();
for ($i = 0; $i < count($request->nombreedificio) ; $i++) {
$edificio = array();
$edificio["nombre_edificio"] = $request->nombreedificio[$i];
$edificio["numero_aulas"] = $request->numeroaulas[$i];
$edificio["prefijo_aulas"] = $request->prefijoaulas[$i];
$edificios[$i] = $edificio;
}
dd($edificios);
When executing a dd ($ buildings); I can observe the following when sending data of two buildings
array:2 [▼
0 => array:3 [▼
"nombre_edificio" => "edificio1"
"numero_aulas" => "10"
"prefijo_aulas" => "a"
]
1 => array:3 [▼
"nombre_edificio" => "edificio2"
"numero_aulas" => "20"
"prefijo_aulas" => "b"
]
]
My question is how can I go through this array, either with a for or a foreach, so that I can iterate the data of each building in this way and save them (SOMETHING TO YES)
for ($c = 0; $c < count($edificios) ; $i++) {
edificio->nombre_edificio[c]
edificio->numero_aulas[c]
edificio->prefijo_aulas[c]
}