How to avoid PHP Notice “Undefined offset: 0” without checking each field of array

后端 未结 5 1166
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 03:27

i have the following array:

    $keyvisual_data = array(
        \'video_file\'            => $row->field_field_video[0][\'rendered\'][\'#item\'][\'uri\'],         


        
5条回答
  •  温柔的废话
    2021-02-05 03:31

    No there is not

    You can do an isset():

    if(isset($array[0])){
        echo $array[0];
    }
    else {
      //some error?
    }
    

    Or if you know that you are only going to be checking index 0:

    $array = $array + array(null);
    

    So if the original $array[0] was unset, now it is null

提交回复
热议问题