本文介绍了如何避免PHP公告"未定义抵消:0"不检查阵列的每个场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数组:

    $keyvisual_data = array(
        'video_file'            => $row->field_field_video[0]['rendered']['#item']['uri'],
        'bild_file'             => $row->field_field_bild[0]['rendered']['#item']['uri'],
        'subline_src'           => $row->_field_data['nid']['entity']->field_key_titel['und'][0]['safe_value'],
        'screenreader_src'      => $row->field_field_alt_screenreader[0]['rendered']['#markup'],
        'alt_src'               => $row->field_field_bild[0]['rendered']['#item']['alt']
    );

可能会发生一些字段没有设置,这是好的。其实我得到这个PHP的通知:

it might happen that some of the fields are not set, this is okay. in fact i am getting this PHP notice:

注意:未定义抵消:在bafa_insert_keyvisual 0()...........

是它在某种程度上可能的情况下,一个默认值分配给每个键它是未定义无需手动检查阵列的每个场?

is it somehow possible to assign a default value to each key in case it is undefined WITHOUT checking each field of the array manually?

感谢您的帮助。

推荐答案

对了,补充 @ 像前场:

$keyvisual_data = array(
    'video_file'            => @$row->field_field_video[0]['rendered']['#item']['uri'],
    'bild_file'             => @$row->field_field_bild[0]['rendered']['#item']['uri'],
    'subline_src'           => @$row->_field_data['nid']['entity']->field_key_titel['und'][0]['safe_value'],
    'screenreader_src'      => @$row->field_field_alt_screenreader[0]['rendered']['#markup'],
    'alt_src'               => @$row->field_field_bild[0]['rendered']['#item']['alt']
);

然后初始化空值:

and then initialize the nulls:

if($keyvisual_data['video_file'] === null)
    $keyvisual_data['video_file'] = $default_video_file;

等等......

etc...

这篇关于如何避免PHP公告"未定义抵消:0"不检查阵列的每个场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 02:00