dqftyn1717 2018-08-18 11:49
浏览 32
已采纳

数组计数+1,网站不加载

I've defined it

$array = array(
"0" => "2",
"1" => "4",
"2" => "6",
"3" => "8",
"4" => "10",
"5" => "12",
"6" => "14",
"7" => "16",
"8" => "18",
"9" => "20",
"10" => "22",
"11" => "24",
"12" => "26",
"13" => "28",
"14" => "30",
"15" => "32"
);

then it should count all numbers from 0 to 16

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

and I use it with $i for the number and $array[$i] for the defined value but it doesn't load, where is my error? btw before that I've tried to question it all like if 0 == ..... and it worked till 10 times repeated then it stopped showing the page.

  • 写回答

1条回答 默认 最新

  • doujiyun0041 2018-08-18 11:58
    关注

    Change $i <= 16; to $i < 16;.

    Your for loop is going past the end of the array you have defined.

    for($i=0; $i < 16; $i++){
        echo $array[$i] . PHP_EOL;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!