循环中未定义的偏移通知 [英] Undefined offset notice in loop

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

问题描述

我正在使用脚本创建其他表单行. 它循环$ i数字为某些文本字段 当我运行此脚本时,偏移量是不确定的,因为它不存在. 我需要使用if(isset())函数,但是不确定如何将其放置在代码中. 有人可以帮忙吗?

I'm using a script to create additional form rows. It loops the $i number for certain text fields When I run this script, the offset is undefined because it doesn't exsist. I need to use the if(isset()) function, but I am unsure how I would place it in the code. Can anyone help?

for ($i=0; $i<100; $i++) {

    if ($text['length'][$i] == "") $text['length'][$i] = "0";
    if ($text['bredth'][$i] == "") $text['bredth'][$i] = "0";
    if ($text['height'][$i] == "") $text['height'][$i] = "0";
    if ($text['weight'][$i] == "") $text['weight'][$i] = "0.00";

以'if'开头的所有行均显示该通知:

All the lines starting with 'if' show the notice:

注意:未定义的偏移量:第41行的C:\ xampp \ htdocs \ newparcelscript.php中的

Notice: Undefined offset: 1 in C:\xampp\htdocs\newparcelscript.php on line 41

已解决 实际上,我根本不需要'if'语句,因为行的创建和值的设置是一起运行的.

SOLVED Infact i did not require and 'if' stament at all, because the creation of the rows and the setting of the values are run together.

for ($i=0; $i<100; $i++) {

   $text['length'][$i] = "0";
   $text['breadth'][$i] = "0";
   $text['height'][$i] = "0";
   $text['weight'][$i] = "0.00";

推荐答案

我认为您正在这里测试empty().

I think testing for empty() is what you're looking for here.

for($i = 0; $i < 100; $i++)
{
    if(empty($text['length'][$i]) === TRUE) $text['length'][$i] = 0;
    ...
    ...
}

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

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