数组帮助
大家好,有一个问题,
我有一个由 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该错误通常意味着您尝试作为数组访问的项目实际上是一个字符串。确保数组中的所有嵌套元素实际上都是数组本身,而不是字符串。
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.