Search code examples
phpxmlreader

XMLReader() in PHP - parsing attributes in multiple elements with the same name


Im using XMLReader to parse XML but i've come across a situation where two elements have the same name and not sure how to deal with it

the elements in question are

<field name="latitude" value="51.4070767"/>
<field name="longitude" value="-0.6366062"/>

I want to pull in the two value fields into seperate strings.

I can pull in the first one using this method

$bp = $product->fields->field["value"]; ###gives 51.4070767

but how do i access the second? (-0.6366062)

Cheers


Solution

  • You need to make field an array, so that you can do:

    $product->fields->field[0]["value"];
    $product->fields->field[1]["value"];