0

这是我的代码:

$xml2  = (array) simplexml_load_string($xml_file);

使用 print_r 这是我的数组:

 Array
(
  [program] => Array
        (
        [0] => SimpleXMLElement Object
        (
            [date] => asgasg sgasgasg
            [start_time] => asdg asg
            [leadtext] => as asdgsagsdgasgasgd
            [name] => as gsadgasg
            [bline] => sag asdg
            [synopsis] => asg asga sdg
            [url] => asg sdgasgasg
        )

        [1] => SimpleXMLElement Object
        (
            [date] => sgasgasg1
            [start_time] => asg1
            [leadtext] => as1
            [name] => gsadgasg1
            [bline] => asdg1
            [synopsis] => sdg1
            [url] =>sdgasgasg1
        )

        )
)

我怎样才能回显从第二个 SimpleXMLElement 获取 [date] 的内容(在上面的示例中是sgasgasg1 )

4

2 回答 2

2

你可以这样做:

echo $xml2['program'][1]->date;
于 2012-10-31T16:45:29.157 回答
2

利用

foreach($xml2['program'] as $key=>$value) {

   echo $value->date;

}

正如你在评论中所说的那样

echo $xml2['program'][1]->date;
于 2012-10-31T16:44:05.620 回答