How to avoid undefined offset

后端 未结 8 2187
梦谈多话
梦谈多话 2020-12-13 05:24

How can you easily avoid getting this error/notice:

Notice: Undefined offset: 1 in /var/www/page.php on line 149

... in this code:

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 06:08

    I'd probably break this up into two steps

    $split = explode('|', $value);
    $func = $split[0];
    if(count($split) > 1)
      $field = $split[1];
    else
      $field = NULL;
    

    There's probably a quicker and neater way though.

提交回复
热议问题