I am REALLY not getting arrays at all, I have read many examples, most plagiarized and amended, am an yet to find help that I understand I do hope someone can walk me through this, so I understand fully.
I have an XML file, which I need to read and display with options to sort using PHP, then output the required fields into my page(s). I have managed to retreive the XML file and rehouse locally and check the age of the file (milestone) and using the code (below) have managed to read the XML file and output as an array, but I can get no further and after two days I turn to you the community for assistance:
<?php
function std_class_object_to_array($stdclassobject) {
$_array = is_object($stdclassobject) ? get_object_vars($stdclassobject) : $stdclassobject;
foreach ($_array as $key => $value) {
$value = (is_array($value) || is_object($value)) ? std_class_object_to_array($value) : $value;
$array[$key] = $value;
}
return $array;
}
$request = $domain.$filename;
$API_results = file_get_contents($request);
$xml = new SimpleXMLElement($API_results);
$Details = std_class_object_to_array($xml);
echo "<pre>";
print_r($Details[hotel]);
echo "</pre>"; ?>
The Output looks like this (shortened)
Array
(
[0] => Array
(
[hotel_ref] => 157258
[hotel_name] => Hotel Kong Arthur
continued
[1] => Array
(
[hotel_ref] => 98813
[hotel_name] => Hotel Lautruppark
Firstly is the code I have used for reading the XML good? Is there a better way that could be used? How do I sort the results? How do I output the individual fields?
Your help, examples and direction would be greatly appreciated,
Stu
//----------------------- UPDATE ----------------------- \
OK, so this is where I am at now with the suggestion to use SimpleXML, but its still not right and I am not really a great deal further on:
$request = $domain.$filename;
$xmlobj = simplexml_load_file($request);
$xml = simplexml_load_file($request) or die("NO XML");
foreach($xml as $hotels)
echo $hotels->hotel_name." (".$hotels->hotel_ref.")<br/>";