PHP Parse XML and group by element.

  • elektric
  • Graduate
  • Graduate
  • User avatar
  • Posts: 130
  • Loc: Mexico

Post 3+ Months Ago

Hello, thank you in advance for your help.

I have been doing some xml to array scripts, the array is fine, but there are results that are alike and need them grouped. E.g.

Hotels

Code: [ Select ]
   ID->1
   Name->Hilton Hotel
     Checkin->jan 15
     Checkout->Jan 20

   ID->9
   Name->Westin Hotel
     Checkin->feb 15
     Checkout->feb 20

   ID->3
   Name->Carlton Hotel
     Checkin->jan 1
     Checkout->Jan 10

   ID->1
   Name->Hilton Hotel
     Checkin->apr 18
     Checkout->apr 25
  1.    ID->1
  2.    Name->Hilton Hotel
  3.      Checkin->jan 15
  4.      Checkout->Jan 20
  5.    ID->9
  6.    Name->Westin Hotel
  7.      Checkin->feb 15
  8.      Checkout->feb 20
  9.    ID->3
  10.    Name->Carlton Hotel
  11.      Checkin->jan 1
  12.      Checkout->Jan 10
  13.    ID->1
  14.    Name->Hilton Hotel
  15.      Checkin->apr 18
  16.      Checkout->apr 25



Notice Hilton hotel appears twise but with different dates, instead of listing the hotel twise I want to list only one Hilton and within the two available dates.

So I get something like this

Code: [ Select ]
hotel[0]
   ID->1
   Name->Hilton Hotel
     Dates[0]
        Checkin->jan 15
        Checkout->Jan 20
     Dates[1]
        Checkin->apr 18
        Checkout->apr 25
hotel[1]
   ID->9
   Name->Westin Hotel
     Dates[0] ->
        Checkin->feb 15
        Checkout->feb 20
hotel[2]
   ID->3
   Name->Carlton Hotel
     Dates[0]
        Checkin->jan 1
        Checkout->Jan 10
  1. hotel[0]
  2.    ID->1
  3.    Name->Hilton Hotel
  4.      Dates[0]
  5.         Checkin->jan 15
  6.         Checkout->Jan 20
  7.      Dates[1]
  8.         Checkin->apr 18
  9.         Checkout->apr 25
  10. hotel[1]
  11.    ID->9
  12.    Name->Westin Hotel
  13.      Dates[0] ->
  14.         Checkin->feb 15
  15.         Checkout->feb 20
  16. hotel[2]
  17.    ID->3
  18.    Name->Carlton Hotel
  19.      Dates[0]
  20.         Checkin->jan 1
  21.         Checkout->Jan 10




Any help will be highly appreciated.

Regards
  • natas
  • PHP Ninja
  • Proficient
  • natas
  • Posts: 308
  • Loc: AFK

Post 3+ Months Ago

can you post your existing code?
  • typhon
  • Guru
  • Guru
  • User avatar
  • Posts: 1294
  • Loc: Memphis, Tn

Post 3+ Months Ago

You might want to look at using simpleXML php extension. From what I have seen it is typically installed with most PHP installs by default.http://php.net/manual/en/book.simplexml.php

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 56 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.