php - Undefined offset error in array index -
i have while loop runs if index of array null. however, when use explode method throws undefined offset error while ($temptext[1] == null). but, if comment explode line out, no longer throws undefined offset error. i'm confused part, because $temptext[1] null whether explodes or not. why 1 of them throwing error, , other 1 isn't? , lastly, how fix this, can use while loop compare empty array index without throwing error?
$temptext = null; $count = 1; $text = ","; $textx = "hello there"; while ($temptext[1] == null && $count > 0) { $count--; $temptext = explode($text,$textx,2); }
p.s: i'm running snippet on phpfiddle.org.
if check existance of array element using $array[1] == null
, php throw notice: undefined offset: 1
, should use !isset($array[1])
instead. otherwise, code contains no errors.
Comments
Post a Comment