1

Why,

  $b = [];
  echo $b[0]; //gives E_NOTICE Undefined offset: 0 

gives notice?

But,

$b = false;
echo $b[0]; // no notice or warnings

var_dump($b[0]) // returns NULL

Could this be due to php.ini settings?

Andrey _
  • 1
  • 2
  • I don't have a direct answer, but I can give you a tips on using `is_array($myVar);` to check if your variable is an array, and then checking if your column is set using `if (isset($b[0])) {}`. – Anwar Sep 14 '16 at 15:32
  • 1
    Because of type inference. Using a variable as certain type makes the interpreter to try to cast it to this type and use it as one. – Royal Bg Sep 14 '16 at 15:34

0 Answers0