Undefined offset 1

tushAR picture tushAR · May 24, 2013 · Viewed 72.1k times · Source

Undefined offset: 1

Hello ... I am facing a problem that undefined offset :1 in line 3. I can't understand that what type of error it is. Can anyone tell me that why such error occurs in php

Undefined offset in line : 3

    foreach ($lines as $line)
    {
      list($var,$value) = explode('=', $line); //line 3
      $data[$var] = $value;
    }

Answer

Nauphal picture Nauphal · May 24, 2013

Your are getting PHP notice because you are trying to access an array index which is not set.

list($var,$value) = explode('=', $line);

The above line explodes the string $line with = and assign 0th value in $var and 1st value in $value. The issue arises when $line contains some string without =.