好吧,我完全被难住了。我发现了类似的问题,但答案似乎不适用于我的具体问题。我已经断断续续地工作了好几天。
我在这里有这个 simplexml 对象(它实际上比这长得多,但我删除了所有无关的东西,所以你会真正看看它):
SimpleXMLElement Object
(
[SubjectClassification] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Authority] => Category Code
[Value] => s
[Id] => s
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Authority] => Subject
[Value] => Sports
[Id] => 54df6c687df7100483dedf092526b43e
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Authority] => Subject
[Value] => Professional baseball
[Id] => 20dd2c287e4e100488e5d0913b2d075c
)
)
)
)
我通过对包含以下内容的变量执行 print_r 得到了这段代码:
$subjects->SubjectClassification->children();
现在,我想获取 subjectClassification 数组的所有元素。他们全部!但是当我这样做时:
$subjects->SubjectClassification;
或这个:
$subjects->SubjectClassification->children();
或者,如果我尝试通过循环获取所有数组元素,我得到的只是:
SimpleXMLElement Object
(
[@attributes] => Array
(
[Authority] => Category Code
[Value] => s
[Id] => s
)
)
为什么?我怎样才能得到一切?