我怎么在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
测试isset($this->arr1['array1']['0']['RACE']),你会知道你是否可以使用它.
您也可以关闭通知(不推荐):
error_reporting(E_ALL ^ E_NOTICE);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4182 次 |
| 最近记录: |