dongzaliang4492 2011-03-25 21:30
浏览 66
已采纳

PHP数组未设置

Here code (executed in php 5.3.5 and 5.2.13):

$res = array(1, 2, 3);

unset($res[0]);

for($i = 0; $i < sizeof($res); $i++)
{
  echo $res[$i] . '<br />';
}

In results i see

<br />2<br />

Why only one element, and first empty? Can`t understand. When doing:

print_r($res);

See:

Array ( [1] => 2 [2] => 3 )

Thanx for help!

  • 写回答

5条回答 默认 最新

  • doupin1073 2011-03-25 21:33
    关注

    This is because you start with $i = 0; rather than 1 which is the new first index. The last element is missing because it stops before the second (previously third) element since the size has been reduced to 2. This should get the results you wish:

    foreach($res as $value) {
        echo $value . '<br />';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)