How to use foreach with PHP & XML (simplexml)

后端 未结 7 850
谎友^
谎友^ 2020-12-10 06:47

Anyone that knows PHP and XML out there? Then please have a look!

This is my PHP code:



        
7条回答
  •  星月不相逢
    2020-12-10 07:37

    You need to iterate through the categorie elements too, in the same way you've iterated through movies.

    echo '

    '; foreach($movie->regions->region->categories->categorie as $categorie){ echo $categorie . ', '; } echo '

    ';

    You'll probably want to trim the trailing , as well.


    The method mentioned in my comment:

    $categories = $movie->regions->region->categories->categorie;
    while($category = current($categories)){
        echo $category . next($categories) ? ', ' : '';
    }
    

提交回复
热议问题