php - 未定义的偏移量

时间:2014-01-13 14:02:03

标签: php

如何修复此未定义的偏移错误。

我得到:Undefined offset 0 - 44, on line 234.

234如下所示:

$mysql['invo_mysql_where'] .= ( $x > 0 ? " OR " : '' )."`id` = {$mysql['inactive'][$x]}";

代码的整个部分如下所示:

shuffle($mysql['inactive']);
        for($x = 0, $l = $mysql['inactive_amount']; $x < $l; $x++){
            $mysql['invo_mysql_where'] .= ( $x > 0 ? " OR " : '' )."`id` = {$mysql['inactive'][$x]}";
        }

$mysql_inactive

$mysql['inactive'] = array();
        if($ile == 10){
            $mysql['inactive_amount'] = mt_rand(0, 1);
        } else if($ile == 20){
            $mysql['inactive_amount'] = mt_rand(0, 2);
        } else if($ile == 30){
            $mysql['inactive_amount'] = mt_rand(0, 3);
        } else if($ile == 40){
            $mysql['inactive_amount'] = mt_rand(0, 4);
        } else if($ile == 50){
            $mysql['inactive_amount'] = mt_rand(0, 4);
        } else if($ile == 60){
            $mysql['inactive_amount'] = mt_rand(1, 3);
        } else if($ile == 70){
            $mysql['inactive_amount'] = mt_rand(2, 3);
        } else if($ile == 80){
            $mysql['inactive_amount'] = mt_rand(3, 4);
        } else if($ile == 90){
            $mysql['inactive_amount'] = mt_rand(4, 4);

        } else if($ile == 100){
            $mysql['inactive_amount'] = mt_rand(5, 5);
        } else if($ile == 200){
            $mysql['inactive_amount'] = mt_rand(6, 5);
        } else {
            $mysql['inactive_amount'] = mt_rand(20, 50);
        }
        $mysql['invo_mysql_where'] = '';

1 个答案:

答案 0 :(得分:0)

问题是您在此处将$mysql['inactive']定义为空数组:

$mysql['inactive'] = array();

然后永远不要添加元素。稍后,您尝试将其用作填充数组:

$mysql['inactive'][$x]

发生错误是因为没有为$mysql['inactive']数组定义索引。为了解决这个问题,您需要使用一些数据填充它。