需要帮助解析xml数组

时间:2014-10-15 01:42:33

标签: php arrays xml

我需要帮助解析我放在PHP数组中的XML文件。我已经尝试过各种我能想到的方式,但我一直都会遇到错误。任何帮助将不胜感激。

Array
(
[question] => Array
    (
        [0] => Array
            (
                [prompt] => From whom did you purchase the property at 222333 PEACHTREE PLACE?
                [type] => purchased.property.from
                [answer] => Array
                    (
                        [0] => A VIRAY
                        [1] => JOE ANDERSON
                        [2] => ANDREW SCHWARZ
                        [3] => None of the above
                    )

            )

        [1] => Array
            (
                [prompt] => When did you purchase or lease your Ford Expedition?
                [type] => vehicle.purchase.date
                [answer] => Array
                    (
                        [0] => September 2004
                        [1] => December 2006
                        [2] => July 2010
                        [3] => None of the above
                    )

            )

        [2] => Array
            (
                [prompt] => What year is your Ford Expedition?
                [type] => vehicle.year
                [answer] => Array
                    (
                        [0] => 2004
                        [1] => 2005
                        [2] => 2006
                        [3] => None of the above
                    )

            )

    )

这是我试图解析的数组。我需要得到提示和答案,就像它们出现一样。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

所以你需要帮助迭代数组?

foreach ($arr['question'] as $question) {
    echo "Prompt: {$question['prompt']}\n";
    foreach ($question['answer'] as $answer) {
        echo "- $answer\n";
    }
}