未定义的偏移量: [英] Undefined offset:

查看:83
本文介绍了未定义的偏移量:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$result = db2_getsub( array('campaigns_id' => $this_id) );

if (!is_null($result))
    {
          $numsub = 0;
    while ( $row = $result->fetch_object() )
        {
            $numsub = $numsub +1;
            array_push($arrFornavn, $row->sub_name);
                    array_push($arrEtternavn, $row->sub_code);
                    }
          $formcountfld=$numsub;
                }
        else
        {
        $numsub=1;
        $formcountfld=1;
        }

            $i = 1;

            if (1==1) {

                for ($i = 1; $i <= $numsub; $i++)
                {
        ?>
          <div class="fieldrow_horz">

            <div class="fieldgroup">
              <input type="text" id="fornavn_<?= $i ?>" name="fornavn_<?= $i ?>" value="<?= $arrFornavn[$i-1] ?>" />
            </div>

            <div class="fieldgroup">
              <input type="text" id="etternavn_<?= $i ?>" name="etternavn_<?= $i ?>" value="<?= $arrEtternavn[$i-1] ?>" />
            </div>

          </div>

          <?php

                    }

            } else {

        ?>

我收到的错误提示:未定义偏移量:0 任何人都可以帮助。在此先感谢您的期待。

I am getting an error as Notice: Undefined offset: 0 can anybody help .thanks in advance looking forward for an answer.

推荐答案

这意味着您正在尝试访问一个不存在的值,在您的情况下为$ arrEtternavn [0]。

It means you are trying to access a value that does not exist, which in your case is $arrEtternavn[0].

小例子:

$array = array();
$array[1] = 'one';
$array[2] = 'two';
$array[4] = 'four';

echo $array[0]; // This will give a notice, $array[0] does not exist.
echo $array[1]; // 'one'
echo $array[2]; // 'two'
echo $array[3]; // This will give a notice, $array[3] does not exist.
echo $array[4]; // 'four'

一个非常简单的解决方法就是:

A very easy fix would me something like this:

value="<?= isset($arrEtternavn[$i-1]) ? $arrEtternavn[$i-1] : '' ?>"

这是一个简短的elseif->(条件)? if_True:if_False

This is a short elseif-> (condition) ? if_True : if_False

编辑:我想补充一点,通知并不是一件坏事。没有通知会是最好的事情,但它不应该让您在晚上醒着。

I'd like to add that a notice isnt a very bad thing. No notices would be the best thing, but it should not keep you awake at night.

这篇关于未定义的偏移量:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆