【问题标题】:error Undefined offset while using explode使用爆炸时出现错误未定义的偏移量
【发布时间】:2015-12-21 22:47:16
【问题描述】:
     $a = explode(",",$data['ids'][$i]);   
  $dbtvalues = array();
                for($j=0;$j< count($a);$j++)
                {   
                    $dbtvalues['serial_no'] =$a[$j];
                    if($data['modelno'] !="select")

                    {
                    $dbtvalues['model_no'] = $data['modelno'][$j];
                    }

                    $dbtvalues['indent_detail_id1'] = (int)$last_id ;
                    $data['indent_req_detail_id'][$i];

                    $this->outpatient_model->insert_row('tra_indent_issue_detail',$dbtvalues);

                }

$a 如果数组有 5 个值,则需要分解并插入到 db 中,必须将 5 行插入到表中。

收到错误消息:

严重性:通知

消息:未定义的偏移量:2

文件名:controllers/indent_receipt.php

行号:71

遇到 PHP 错误

严重性:通知

消息:未定义的偏移量:3

文件名:controllers/indent_receipt.php

行号:71

遇到 PHP 错误

严重性:通知

消息:未定义的偏移量:4

文件名:controllers/indent_receipt.php

行号:71

遇到 PHP 错误

严重性:通知

消息:未定义的偏移量:5

文件名:controllers/indent_receipt.php

行号:71

遇到 PHP 错误

严重性:通知

消息:未定义的偏移量:2

文件名:controllers/indent_receipt.php

行号:71

提前致谢。

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    索引不存在。这就是为什么会出现警告

    $a=array();
    if(!empty($data['ids'][$i]))
    $a = explode(",",$data['ids'][$i]);
    

    如果条件在索引不为空时工作,则放在上面。

    【讨论】:

    • 你是怎么知道第 71 行的??
    猜你喜欢
    • 1970-01-01
    • 2013-01-26
    • 1970-01-01
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-22
    • 1970-01-01
    相关资源
    最近更新 更多