Question

I have this object returned:

Array 
( 
[0] => SimpleXMLElement Object 
( 
    [@attributes] => Array 
    ( 
        [Desc] => Amount should be numeric. 
    ) 
) 
[1] => SimpleXMLElement Object 
( 
    [@attributes] => Array 
    ( 
        [Desc] => Please enter your Reference Number. 
    ) 
) 
)

How can I get the desc values? I need to get both Desc Values('Amount should be numeric.' and 'Please enter your Reference Number. ')

I have tried:

$res = $str[0];

it returned:

SimpleXMLElement Object 
( 
    [@attributes] => Array 
    ( 
        [Desc] => Amount should be numeric. 
    ) 
 ) 
Was it helpful?

Solution 2

Call attributes() and then access them as properties.

$node->attributes()->Desc

OTHER TIPS

Your object is a SimpleXML object.

You can learn how to use it here:

http://php.net/manual/fr/book.simplexml.php

To solve your issue, you can use this:

$res0 = $str[0]->attributes()->Desc;
$res1 = $str[1]->attributes()->Desc;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top