0

I want to load all xml values into array

for example, i've the following xml

<rating>
<kp_rating num_vote="14008">8.665</kp_rating>
<imdb_rating num_vote="94758">8.8</imdb_rating>
</rating>

using Simplexml_load_string i'm getting only

SimpleXMLElement Object ( [kp_rating] => 8.665 [imdb_rating] => 8.8 )

How can I get in addition the num_vote?

1 Answer 1

1

You can access the node attributes using the array access syntax:

$xml->kp_rating['num_vote']
$xml->imdb_rating['num_vote']

From the documentation:

SimpleXML can also access element attributes. Access attributes of an element just as you would elements of an array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.