Guest User

Untitled

a guest
Jan 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. <?php
  2. $input = <<<'XML'
  3. <?xml version="1.0" encoding="UTF-8"?>
  4. <apps>
  5. <app id="1">
  6. <name>Blah</name>
  7. <price locale="sv">19.31</price>
  8. <price locale="no">16.39</price>
  9. <price locale="da">15.65</price>
  10. <price locale="all">2.12</price>
  11. </app>
  12. </apps>
  13. XML;
  14. $xml = new SimpleXMLElement($input);
  15. $apps = array();
  16.  
  17. foreach ($xml as $node) {
  18. $app = array('name' => (string)$node->name, 'price' => array());
  19.  
  20. foreach ($node->price as $price) {
  21. $locale = (string)$price['locale'];
  22. $app['price'][$locale] = (float)$price;
  23. }
  24.  
  25. array_push($apps, $app);
  26. }
Add Comment
Please, Sign In to add comment