且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过密钥直接访问XML节点

更新时间:2023-12-02 23:40:16

Why is it unsetting something it hasn't displayed?这不是您的情况.当您取消设置已处理的项目时,数组数据正在移位...索引1处的前一个元素获得索引0,2移至1,依此类推.因此,如果您在未设置$ element [0]后访问$ element [1],您将获得位于$ element [2]位置的元素,因为前一个$ element [1]移至$ element [0]且$ element [2]到$ element [1].

Why is it unsetting something it hasn't displayed? That's not what is happening in your case. When you unset the processed item, the array-data are shift... the former element at index 1 get the index 0, 2 moves to 1 and so on. So if you access $element[1] after you have unset $element[0] you'll get the element that was at position $element[2], because the former $element[1] moved to $element[0] and $element[2] to $element[1].

如果您始终取消设置已处理的元素,则可以通过在每次迭代中访问$ element [0]来实现,如果数组为空,则可以取消.

If you always unset the processed element, you can do it by accessing $element[0] on each iteration an cancel if the array is empty.


// ...
while ($array) {               // same as count($array)
  $currentElement = $array[0];
  // do something
  unset($array[0]);
}
// ...