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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -