如何显示来自 SimpleXML 对象的值(数组符号让我感到困惑)

How to display a value from a SimpleXML object (the array notation is confusing me)

我有一个 PHP 文件,它使用 cURL 检索一些 XML。我现在想从 XML 中检索一个值,但我无法遍历它,因为我对符号感到困惑。

这是我检索到的 XML:

SimpleXMLElement Object
(
[@attributes] => Array
    (
        [uri] => /fruit/apple/xml/green/pipType
    )

[result] => SimpleXMLElement Object
    (
        [JobOpenings] => SimpleXMLElement Object
            (
                [row] => Array
                    (
                        [0] => SimpleXMLElement Object
                            (
                                [@attributes] => Array
                                    (
                                        [no] => 1
                                    )
                                [FL] => Array
                                    (
                                        [0] => 308343000000092052
                                        [1] => ZR_6_JOB
                                    )
                            )
                        [1] => SimpleXMLElement Object
                            (
                                [@attributes] => Array
                                    (
                                        [no] => 2
                                    )
                                [FL] => Array
                                    (
                                        [0] => 308343000000091031
                                        [1] => ZR_5_JOB
                                    )
                            )
                    )
            )
    )
)

我将这个 XML 存储在一个名为 $xml 的变量中,使用:

$xml = new SimpleXmlElement($data, LIBXML_NOCDATA);

关于如何 select ZR_5_JOB 元素有什么帮助吗?

我试过无数次,最后的努力是:

print_r($xml->result->JobOpenings->row[0]->FL[0]);

有人可以帮忙吗?

(我知道我需要做一些迭代,但我会稍后处理!)

首先循环 JobOpenings 行以分别获取每一行,然后您可以轻松访问该元素的子元素。

foreach($xml->result->JobOpenings->row as $item) {
    echo $item->FL[0] . '<br>';
}