未定义的偏移误差,新增建筑阵列



我正在学习数组并将其放在一起...它的工作原理意味着我得到了我想要的结果,但我得到了未定义的偏移错误。

$err_数组 = 数组();$err_array[0] = array('步骤 1 和 2 为空.','chu');$err_array[1] = array('Step 1 为空(但可选) a','Step 1 为空(但可选)');$err_array[2] = array(' 步骤 2 为空(且是必需的)','步骤 2 为空(且是必需的)');$err_array[3] = array(' 步骤 3 为空(且为必填)','步骤 3 为空(且必需);$err_array[4] = array(' 步骤 4 为空(和可选)','步骤 4 为空(和可选)');        # 设置错误消息的文本颜色    $counter = 0;          # 第 16 行 while (is_array($err_array[$counter]) {                  $err_[$counter] = ''.$err_array[$counter][0].'';# 第 18 行 $err__[$counter] = ''.$err_array[$counter][1].'';            $counter++;            }

这是错误:

注意:未定义的偏移量:第 5 行/nfs/c08/h04/mnt/124078/domain/yourinternetfootprint.com/html/wp-content/plugins/wordpress_meta_box_sample_files/include/template_yif_ealfm_get_rss_feed_parameters.php 在第 16 行

注意:未定义的偏移量:1 in/nfs/c08/h04/mnt/124078/domain/yourinternetfootprint.com/html/wp-content/plugins/wordpress_meta_box_sample_files/include/template_yif_ealfm_get_rss_feed_parameters.php 在第 18 行

我知道有一种更干净的方法来获取错误消息并将它们分配给变量并围绕它们包装一些 css......但正如我所说,我正在学习。

要正确迭代$err_array,您应该使用 foreach

foreach ($err_array as $counter => $errors) {
    if (isset($errors[0])) { // make sure $errors[0] exists
        $err_[$counter] = $errors[0];
    }
    if (isset($errors[1])) { // make sure $errors[1] exists
        $err__[$counter] = $errors[1];
    }
}

最新更新