0
Well, in case I have two arrays that are received from inputs, based on renting rooms from a hotel, in case each room needs to display number of adults and children, I got help from someone here in the stack to increase the number of rooms, but had to put below the adults the $Children array, in this case, children for each room, but this giving error here, someone knows if it is possible to do?
$adultos = array(2, 3, 2);
$criancas = array(1, 1, 3);
$i = 1;
foreach($adults as $adultos):
echo "<strong>Quarto".$i++."</strong><br>";
echo "Adultos:".$adultos."<br>";
//AQUI PRECISAVA EXIBIR AS CRIANÇAS
echo "Crianças:".$criancas."<br>";
endforeach;
I’m hitting myself here to do this, if anyone can shed a light...
Both arrays will have at all times the same number of elements or this is not guaranteed?
– Woss
If not, what is the relationship between adults and children? Why do they need to be together?
– Maniero
I wouldn’t particularly iterate with
foreach
in this case. It seems that the data structure was not made imagining this kind of iteration. This is a frame of reference by the index, so you are most likely doomed to use the index (or convert into another data structure, using the index as possibly intermediate)– Jefferson Quesado