I'm trying to read an XML file into an array and I'm having a little bit of trouble. Here is what my code looks like so far:
 $inst = new SimpleXMLElement($xml);
 foreach( $inst->xpath("record[@id='" . $range . "']") as $u ) {
      foreach($fields as $field) {
          $results[$field] = $u->$field;
      }
 }
But when I do print_r($results), this is what's outputted:
Array
(
[field1] => SimpleXMLElement Object
    (
        [0] => field1Data
    )
[field2] => SimpleXMLElement Object
    (
        [0] => field2Data
    )
[field3] => SimpleXMLElement Object
    (
        [0] => field3Data
    )
)
How can I get the data straight from the SimpleXMLElement Object and store it in the array rather than having it do this? I tried accessing it as an array like $u->$field[0] but that didn't work either.
 
     
    