我怎么在PHP中来到未定义的偏移0通知

Som*_*one 1 php

我怎么在PHP中来到未定义的偏移0通知

我在php中有一些语句,其中包含一些导致此通知的数组.但是inoorder在php中使用empty()来解决这个问题.

$val= array(    
    'codes' => $this->arr1['BAC'],
    'lines' => $this->arr1['array1'][0]['RACE']  // this is the statement causing undefined offset 0
);

if(!empty( $this->arr1['array1'])){
$val= array(    
    'codes' => $this->arr1['BAC'],
    'lines' => $this->arr1['array1'][0]['RACE']  // this is the statement causing undefined offset 0
);
}
Run Code Online (Sandbox Code Playgroud)

以上是推荐的.但我的问题是,如果我把它们放入if().可以在if()之外访问$ val

Gus*_*son 5

测试isset($this->arr1['array1']['0']['RACE']),你会知道你是否可以使用它.

您也可以关闭通知(不推荐):

error_reporting(E_ALL ^ E_NOTICE);
Run Code Online (Sandbox Code Playgroud)