0

我返回了这个对象:

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

我怎样才能得到 desc 值?我需要同时获取 Desc 值('金额应该是数字。'和'请输入您的参考号。')

我努力了:

$res = $str[0];

它返回:

SimpleXMLElement Object 
( 
    [@attributes] => Array 
    ( 
        [Desc] => Amount should be numeric. 
    ) 
 ) 
4

2 回答 2

2

您的对象是一个 SimpleXML 对象。

你可以在这里学习如何使用它:

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

要解决您的问题,您可以使用以下方法:

$res0 = $str[0]->attributes()->Desc;
$res1 = $str[1]->attributes()->Desc;
于 2013-09-25T09:07:28.930 回答
1

调用attributes()然后将它们作为属性访问。

$node->attributes()->Desc
于 2013-09-25T09:05:47.010 回答