2011-09-29 56 views
0

的价值我尝试了太多的事情,从下面的代码读取[标签]的值:得到SimpleXMLElement对象的PHP

Array ([0] => 
    SimpleXMLElement Object 
    (
     [id] => x 
     [published] => 2011 
     [category] => 
    Array ([0] => 
     SimpleXMLElement Object 
     ( 
     [@attributes] => 
     Array (
     [scheme] => y 
     [term] => t 
     )) 
     [1] => SimpleXMLElement Object 
     ([@attributes] => 
     Array (
     [scheme] => y2 
     [term] => Film 
     [label] => Film & Animation 
     )) 

它与数字阵列开始。

+1

的可能重复[PHP得到的SimpleXMLElement阵列值(http://stackoverflow.com/questions/2751711/ php-get-values-from-simplexmlelement-array),另见[手册中的基本用法示例](http://fr.php.net/manual/en/simplexml.examples-basic.php)。 – hakre

+0

坦克,我看到了那些,但它没有为我工作,它有2个暗淡的阵列......真的有进展: – user972087

回答

0

是不是你的答案简单:

$data->category['label']? 

见SimpleXML的文档接下来的时间,所有的属性都是从一个数组访问,并且所有子节点通过对象属性操作员访问。

如果你有很多类,那么你将不得不在一个阵列“类别[0]”

+0

哦,等等,我没有看到正确的结构,它实际上是:$ data-> category [1] ['label'] –

+0

你可以编辑你的答案。 – someone