本文介绍了使用foreach循环下一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是通过一个数组使用的foreach循环。

I am looping through an array using foreach.

在特定的情况下,我需要知道下一个元素的值之前迭代来了(如prediction)元素。对于我计划用函数。

In a particular situation I need to know the value of the next element before iteration comes to that(like a prediction) element. For that I am planning to use the function next().

在文档我只注意到,明年()推进内部数组指针向前发展。

In documentation I just noticed that next() advances the internal array pointer forward.

next()的行为就像电流(),有一个区别。它推进
  内部数组指针一个地方向前返回元素之前
  值。这意味着它返回下一个数组值和推进
  通过一个内部数组指针。

如果这样会影响我的foreach循环?

If so will it affect my foreach loop?

推荐答案

这不会影响你的循环
如果以这种方式来使用它。

It will not affect your loopif you use it in this way

<?php

$lists = range('a', 'f');

foreach($lists as &$value) {
   $next = current($lists);
   echo 'value: ' . $value . "\n" . 'next: ' . $next . "\n\n";
}

输出

值:一个
  接下来是b

值:B
  下一:C

value: b next: c

值:C
  接下来:D

value: c next: d

值:D
  接下来:电子

value: d next: e

值:电子
  接下来:F

value: e next: f

值:F
  下一篇:

value: f next:

这篇关于使用foreach循环下一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 09:59