Ok here's my dilemma. I am looking for a way to consolidate the data in a group using SimpleXML in PHP. Here's what I mean.
Let's say I have an xml that looks like this:
<favorites>
<interesting>
<type>Movie</type>
<character>James Bond</character>
<name>Casino Royale</name>
</interesting>
<interesting>
<type>Movie</type>
<character>Jason Bourne</character>
<name>Bourne Identity</name>
</interesting>
<interesting>
<type>Book</type>
<character>Lindsay Ford</character>
<name>Shantaram</name>
</interesting>
</favorites>
Now here's what I want that to look like:
Movie
- Casino Royale - James Bond Bourne
- Bourne Identity - Jason Bourne
Book
- Shantaram - Lindsay Ford
Please help me!! Let me know if anything is confusing.
I believe you are looking for Xpath:
You can then loop over $arrMovies and $arrBooks and print out what you need:
If you don't know in advance the types of movies, you could :
array_unique
)Something like this would probably do :
And to make things easier to understand, here are the var_dump's outputs :
var_dump #1 :
var_dump #2 :
var_dump #3 :
var_dump #3 :
Now, it's up to you to present those data the way you want ; a double-foreach loop constructing
<ul>
and<li>
tags would probably do ;-)