-1

我有这个数组,它是从 web 服务中得到的,所以我得到的数组是一个带有数据的 XML。我想打印每个我不知道该怎么做的寄存器。我尝试了很多方法来打印它,但我不能。

Array

(
    [Record] => Array
        (
            [0] => stdClass Object
                (
                    [Field] => Array
                        (
                            [0] => licsa
                            [1] => b0z833
                            [2] => 1381768597
                            [3] => 0xF447
                            [4] => -12.047333333333333
                            [5] => -77.12163333333334
                            [6] => 0.0
                            [7] => Licsa
                            [8] => licsa
                        )
                )
            [1] => stdClass Object
                (
                    [Field] => Array
                        (
                            [0] => licsa
                            [1] => b0z834
                            [2] => 1381767415
                            [3] => 0x000C
                            [4] => -12.047633333333334
                            [5] => -77.12366666666667
                            [6] => 0.0
                            [7] => Licsa
                            [8] => licsa
                        )

                )

        )

)


Array ( [Record] => Array ( [0] => stdClass Object ( [Field] => Array ( [0] => licsa [1] => b0z833 [2] => 1381768597 [3] => 0xF447 [4] => -12.047333333333333 [5] => -77.12163333333334 [6] => 0.0 [7] => Licsa [8] => licsa ) ) [1] => stdClass Object ( [Field] => Array ( [0] => licsa [1] => b0z834 [2] => 1381767415 [3] => 0x000C [4] => -12.047633333333334 [5] => -77.12366666666667 [6] => 0.0 [7] => Licsa [8] => licsa ) ) ) ) 1

打印我使用的....

4

3 回答 3

0

要将 XML 转换为数组,假设原始数组在 inside $xml_original,请执行以下操作:

$xml_array = unserialize(serialize(json_decode(json_encode((array) $xml_original), 1)));

此时所有对象都应转换为数组。

于 2013-10-14T18:20:23.783 回答
0

使用 访问数组,使用 访问数组$array['key']stdClass因此$object->key根据您的print_r输出,您必须使用以下方法访问它:

echo 'licsa = ' . $array['Record'][0]->Field[0];

等等

你也可以遍历它:

foreach ($array['Record'] as $record) {
    echo 'licsa = ' . $record->Field[0];
}
于 2013-10-14T18:25:02.617 回答
0

有点模糊,但尝试:

foreach($array['Record'] as $object) {
    foreach($object->Field as $value) {
        echo $value;
    }
} 
于 2013-10-14T17:20:49.783 回答