0

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

2 Answers 2

2

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;
Sign up to request clarification or add additional context in comments.

Comments

1

Call attributes() and then access them as properties.

$node->attributes()->Desc

6 Comments

This answer is the same with scalpweb. Thanks too.
@Ponce Certainly is. But looking at the post date/time, it might be worth flipping the subjects :)
@Scalpweb answered it 2minutes earlier. And I can only choose one. so far both works well.
@Ponce You must have funny views on how time works :) Anyway, I'm not worried.
oh sry.. my mind is conjested cant think properly, nearly done though. edited accepted answer. Thank you again
|

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.