Search code examples
phparraysarrayobject

An array within an array of object


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. 
    ) 
 ) 

Solution

  • Call attributes() and then access them as properties.

    $node->attributes()->Desc