There are xml:

<planeta-kino> <movies>...</movies> <showtimes> <day date="2017-03-04"> <show full-date="2017-03-04 17:20:00" /> <show full-date="2017-03-04 21:45:00" /> <show full-date="2017-03-04 10:30:00" /> ... <day date="2017-03-05"> <show full-date="2017-03-05 17:20:00" /> <show full-date="2017-03-05 21:45:00" /> <show full-date="2017-03-05 10:30:00" /> ... итд 

I use 2 cycles to go over all <day> and all <show> nested

 foreach ($data->showtimes->day as $day){ foreach ($data->showtimes->day->show as $show){ echo $show['full-date']."<br>"; } } 

But I always get the result only on the first block <day> <show>

2017-03-04 17:20:00
2017-03-04 21:45:00
2017-03-04 10:30:00
2017-03-04 17:20:00
2017-03-04 21:45:00
2017-03-04 10:30:00
... etc

those. always for 2017-03-04 number and how can I not get to the 2nd block <show>. What's wrong with my cycle, tell me?

  • I gave the answer in a similar question, try this solution - Alexey Presman

2 answers 2

Try

 foreach ($data->showtimes->day as $day){ foreach ($day->show as $show){ echo $show['full-date']."<br>"; } } 
  • thanks, worked - Alex Sokolov

In the internal foreach you need to use the resulting variable from the external foreach , otherwise it does not make sense.

 foreach ($data->showtimes->day as $day){ | ------------------------ ↓ foreach ($day->show as $show){ echo $show['full-date']."<br>"; } } 
  • so it is, now it works as it should, thanks - Alex Sokolov
  • @AlexSokolov Our site is different from social networks. It helps to solve applied problems. Therefore, we use comments only on the case - to clarify the problem, to give constructive criticism or add useful information. To thank the author of the answer, vote for the answer or mark it as a decision. ru.stackoverflow.com/help/someone-answers - Crantisz