数组帮助

发布于 2024-11-19 06:17:48 字数 7899 浏览 4 评论 0原文

大家好,有一个问题,

我有一个由 Web 服务返回的数组。

Array
(
[GetProductResult] => Array
    (
        [schema] => Array
            (
                [element] => Array
                    (
                        [complexType] => Array
                            (
                                [choice] => Array
                                    (
                                        [element] => Array
                                            (
                                                [complexType] => Array
                                                    (
                                                        [sequence] => Array
                                                            (
                                                                [element] => Array
                                                                    (
                                                                        [0] => Array
                                                                            (
                                                                                [!name] => codigo
                                                                                [!minOccurs] => 0
                                                                            )

                                                                        [1] => Array
                                                                            (
                                                                                [!name] => nome
                                                                                [!minOccurs] => 0
                                                                            )

                                                                        [2] => Array
                                                                            (
                                                                                [!name] => imagem
                                                                                [!minOccurs] => 0
                                                                            )

                                                                        [3] => Array
                                                                            (
                                                                                [!name] => stock
                                                                                [!minOccurs] => 0
                                                                            )

                                                                    )

                                                            )

                                                    )

                                                [!name] => produto
                                            )

                                        [!minOccurs] => 0
                                        [!maxOccurs] => unbounded
                                    )

                            )

                        [!name] => produtos
                        [!msdata:IsDataSet] => true
                        [!msdata:UseCurrentLocale] => true
                    )

                [!id] => produtos
            )

        [diffgram] => Array
            (
                [produtos] => Array
                    (
                        [produto] => Array
                            (
                                [codigo] => 13251
                                [nome] => Nova Development - Print Explosion Deluxe Mac
                                [imagem] => http://www.novadevelopment.com/images/3DBox_w250_tcm23-129399.jpg
                                [stock] => 0
                                [!diffgr:id] => produto1
                                [!msdata:rowOrder] => 0
                            )

                    )

            )

    )

我使用数据库中的 id_produto 从网络服务请求,但有时我收到此错误:

无法在 php 中将字符串偏移量用作数组

,并且数组结果是

Array
(
[GetProductResult] => Array
    (
        [schema] => Array
            (
                [element] => Array
                    (
                        [complexType] => Array
                            (
                                [choice] => Array
                                    (
                                        [element] => Array
                                            (
                                                [complexType] => Array
                                                    (
                                                        [sequence] => Array
                                                            (
                                                                [element] => Array
                                                                    (
                                                                        [0] => Array
                                                                            (
                                                                                [!name] => codigo
                                                                                [!minOccurs] => 0
                                                                            )

                                                                        [1] => Array
                                                                            (
                                                                                [!name] => nome
                                                                                [!minOccurs] => 0
                                                                            )

                                                                        [2] => Array
                                                                            (
                                                                                [!name] => imagem
                                                                                [!minOccurs] => 0
                                                                            )

                                                                        [3] => Array
                                                                            (
                                                                                [!name] => stock
                                                                                [!minOccurs] => 0
                                                                            )

                                                                    )

                                                            )

                                                    )

                                                [!name] => produto
                                            )

                                        [!minOccurs] => 0
                                        [!maxOccurs] => unbounded
                                    )

                            )

                        [!name] => produtos
                        [!msdata:IsDataSet] => true
                        [!msdata:UseCurrentLocale] => true
                    )

                [!id] => produtos
            )

        **[diffgram] =>**
    )

:)

现在我如何避免此错误?我试图用这个访问数组:

$stock = $result['GetProductResult']['diffgram']['produtos']['produto']['stock'];

有人可以帮助一个 If 来传递错误吗?

康普斯

Hello people a have a problem,

I have a array returned by webservice.

Array
(
[GetProductResult] => Array
    (
        [schema] => Array
            (
                [element] => Array
                    (
                        [complexType] => Array
                            (
                                [choice] => Array
                                    (
                                        [element] => Array
                                            (
                                                [complexType] => Array
                                                    (
                                                        [sequence] => Array
                                                            (
                                                                [element] => Array
                                                                    (
                                                                        [0] => Array
                                                                            (
                                                                                [!name] => codigo
                                                                                [!minOccurs] => 0
                                                                            )

                                                                        [1] => Array
                                                                            (
                                                                                [!name] => nome
                                                                                [!minOccurs] => 0
                                                                            )

                                                                        [2] => Array
                                                                            (
                                                                                [!name] => imagem
                                                                                [!minOccurs] => 0
                                                                            )

                                                                        [3] => Array
                                                                            (
                                                                                [!name] => stock
                                                                                [!minOccurs] => 0
                                                                            )

                                                                    )

                                                            )

                                                    )

                                                [!name] => produto
                                            )

                                        [!minOccurs] => 0
                                        [!maxOccurs] => unbounded
                                    )

                            )

                        [!name] => produtos
                        [!msdata:IsDataSet] => true
                        [!msdata:UseCurrentLocale] => true
                    )

                [!id] => produtos
            )

        [diffgram] => Array
            (
                [produtos] => Array
                    (
                        [produto] => Array
                            (
                                [codigo] => 13251
                                [nome] => Nova Development - Print Explosion Deluxe Mac
                                [imagem] => http://www.novadevelopment.com/images/3DBox_w250_tcm23-129399.jpg
                                [stock] => 0
                                [!diffgr:id] => produto1
                                [!msdata:rowOrder] => 0
                            )

                    )

            )

    )

)

i request from a webservice using id_produto from my Database but sometimes i got this error:

Cannot use string offset as an array in php

AND ARRAY RESULT IS:

Array
(
[GetProductResult] => Array
    (
        [schema] => Array
            (
                [element] => Array
                    (
                        [complexType] => Array
                            (
                                [choice] => Array
                                    (
                                        [element] => Array
                                            (
                                                [complexType] => Array
                                                    (
                                                        [sequence] => Array
                                                            (
                                                                [element] => Array
                                                                    (
                                                                        [0] => Array
                                                                            (
                                                                                [!name] => codigo
                                                                                [!minOccurs] => 0
                                                                            )

                                                                        [1] => Array
                                                                            (
                                                                                [!name] => nome
                                                                                [!minOccurs] => 0
                                                                            )

                                                                        [2] => Array
                                                                            (
                                                                                [!name] => imagem
                                                                                [!minOccurs] => 0
                                                                            )

                                                                        [3] => Array
                                                                            (
                                                                                [!name] => stock
                                                                                [!minOccurs] => 0
                                                                            )

                                                                    )

                                                            )

                                                    )

                                                [!name] => produto
                                            )

                                        [!minOccurs] => 0
                                        [!maxOccurs] => unbounded
                                    )

                            )

                        [!name] => produtos
                        [!msdata:IsDataSet] => true
                        [!msdata:UseCurrentLocale] => true
                    )

                [!id] => produtos
            )

        **[diffgram] =>**
    )

)

Now how i avoid this error? im trying to access to array with this:

$stock = $result['GetProductResult']['diffgram']['produtos']['produto']['stock'];

Someone can help with one If to pass the error?

Cumps

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぺ禁宫浮华殁 2024-11-26 06:17:48

该错误通常意味着您尝试作为数组访问的项目实际上是一个字符串。确保数组中的所有嵌套元素实际上都是数组本身,而不是字符串。

That error usually means that at item that you are trying to access as an array is actually a string. Make sure that all of the nested elements in your arrays are actually arrays themselves, and not strings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文