PHP 解析 soapClient 响应传输到 table

PHP parse soapClient response transfer to a table

我只是在软管上,不要继续。

我不是专业的程序员,但到目前为止,通过大量阅读和无数次尝试,到目前为止,一切都创造了我所做的一切,只有这样我才可能找到了我的杰作。

我有一个 SOAP 查询的响应,我想在 table 中显示每个 powerUnitidentifier 的值。最好的方法是什么?

(
    [RawData] => stdClass Object
        (
            [from] => 2022-05-10T01:00:00+02:00
            [to] => 2022-05-10T01:20:00+02:00
            [dataRecords] => stdClass Object
                (
                    [record] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [powerUnitIdentifier] => abc123
                                    [time] => 2022-05-10T01:00:00+02:00
                                    [fields] => stdClass Object
                                        (
                                            [field] => Array
                                                (
                                                    [0] => stdClass Object
                                                        (
                                                            [identifier] => 100
                                                            [value] => 0
                                                        )

                                                    [1] => stdClass Object
                                                        (
                                                            [identifier] => 101
                                                            [value] => 3.27
                                                        )

                                                    [2] => stdClass Object
                                                        (
                                                            [identifier] => 102
                                                            [value] => 70.00
                                                        )

                                                )

                                        )

                                )

                            [1] => stdClass Object
                                (
                                    [powerUnitIdentifier] => zyx321
                                    [time] => 2022-05-10T01:00:00+02:00
                                    [fields] => stdClass Object
                                        (
                                            [field] => Array
                                                (
                                                    [0] => stdClass Object
                                                        (
                                                            [identifier] => 100
                                                            [value] => 0
                                                        )

                                                    [1] => stdClass Object
                                                        (
                                                            [identifier] => 101
                                                            [value] => 3.19
                                                        )

                                                    [2] => stdClass Object
                                                        (
                                                            [identifier] => 102
                                                            [value] => 70.00
                                                        )

                                                )

                                        )

                                )

                            [2] => stdClass Object
                                (
                                    [powerUnitIdentifier] => abc123
                                    [time] => 2022-05-10T01:10:00+02:00
                                    [fields] => stdClass Object
                                        (
                                            [field] => Array
                                                (
                                                    [0] => stdClass Object
                                                        (
                                                            [identifier] => 100
                                                            [value] => 0
                                                        )

                                                    [1] => stdClass Object
                                                        (
                                                            [identifier] => 101
                                                            [value] => 3.15
                                                        )

                                                    [2] => stdClass Object
                                                        (
                                                            [identifier] => 102
                                                            [value] => 70.00
                                                        )

                                                )

                                        )

                                )

                            [3] => stdClass Object
                                (
                                    [powerUnitIdentifier] => zyx321
                                    [time] => 2022-05-10T01:10:00+02:00
                                    [fields] => stdClass Object
                                        (
                                            [field] => Array
                                                (
                                                    [0] => stdClass Object
                                                        (
                                                            [identifier] => 100
                                                            [value] => 0
                                                        )

                                                    [1] => stdClass Object
                                                        (
                                                            [identifier] => 101
                                                            [value] => 3.09
                                                        )

                                                    [2] => stdClass Object
                                                        (
                                                            [identifier] => 102
                                                            [value] => 70.00
                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

)```

您遍历数据部分,在数据结构的正确级别开始 foreach 循环

foreach($theName->RawData->DataRecords->record as $obj) {
    echo $obj->powerUnitIdentifier;
}

或者如果你想处理那个

的子数组
foreach($theName->RawData->DataRecords->record as $obj) {
    echo $obj->powerUnitIdentifier . '<br>';
    foreach( $obj->fields as $field) {
        echo $field->identifier . ',' . $field->value . '<br>';
    }
}