satish kilari
satish kilari

Reputation: 728

error Undefined offset while using explode

     $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 need to explode and insert into db if array has 5 values 5 rows must be inserted into table.

getting error message as :

Severity: Notice

Message: Undefined offset: 2

Filename: controllers/indent_receipt.php

Line Number: 71

A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 3

Filename: controllers/indent_receipt.php

Line Number: 71

A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 4

Filename: controllers/indent_receipt.php

Line Number: 71

A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 5

Filename: controllers/indent_receipt.php

Line Number: 71

A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 2

Filename: controllers/indent_receipt.php

Line Number: 71

thanks in advance.

Upvotes: 0

Views: 814

Answers (1)

Man Programmer
Man Programmer

Reputation: 5356

Index is not exists. that why warning occurs

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

Put above if condition it's working when index is not empty.

Upvotes: 1

Related Questions