Iyad
Iyad

Reputation: 163

capture the value of an element in array returned by simpleXML in PHP?

Any idea how can i get a single value from an element in array returned by an XML which looks like this?

SimpleXMLElement Object
(
[status] => SimpleXMLElement Object
    (
        [id] => 0
        [description] => Success
    )
    ......

I want to capture the [id] and return that value to run tests against it.

the above was captured using the following

$xml = simplexml_load_string($result);

Thanks

Upvotes: 0

Views: 68

Answers (2)

Andreas Wong
Andreas Wong

Reputation: 60584

Are you looking for something like:

$sxml = new SimpleXMLElement("<statuses><status><id>0</id><description>success</description></status></statuses>");
var_dump((string) $sxml->status[0]->id);

Upvotes: 0

Chirag
Chirag

Reputation: 1128

Try this $id = $xml->status->id;

Upvotes: 1

Related Questions