PHP的 - 如何解决这种非法抵消类型的错误 [英] php - How do I fix this illegal offset type error

查看:358
本文介绍了PHP的 - 如何解决这种非法抵消类型的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到非法偏移类型错误此code的每一次迭代。下面是任何人的情况下在code可以帮助:

I'm getting "illegal offset type" error for every iteration of this code. Here's the code in case anyone can help:

$s = array();

for($i=0;$i<20;$i++){

    $source = $xml->entry[$i]->source;
    $s[$source] += 1;

}

print_r($s)

任何想法。先谢谢了。

Any ideas. Thanks in advance.

推荐答案

非法抵消类型的当您尝试使用的目标或访问数组索引发生错误< STRONG>阵列作为索引键。

Illegal offset type errors occur when you attempt to access an array index using an object or an array as the index key.

例如:

$x = new stdClass();
$arr = array();
echo $arr[$x];
//illegal offset type

$ XML 数组包含在 $ XML的&GT的对象或数组;进入[$ i] - &GT;源 $ I ,并且当您尝试使用为 $ S ,你会得到警告。你必须确保 $ XML 包含您希望它和你正确地访问它的东西。

Your $xml array contains an object or array at $xml->entry[$i]->source for some value of $i, and when you try to use that as an index key for $s, you get that warning. You'll have to make sure $xml contains what you want it to and that you're accessing it correctly.

这篇关于PHP的 - 如何解决这种非法抵消类型的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆