我有一个foreach循环,希望可以知道是否还有下一个元素,这样就能将当前元素与下一个元素进行比较。我该如何做?我已经了解了current和next函数,但是不知道如何使用它们。
$next_data = $data;
$prev_key = null;
$prev_value = null;
foreach($data as $key => $value)
{
array_shift($next_data);
$next_key = key($next_data);
$next_value = $next_data[$next_key] ?? null;
// Do something here...
$prev_key = $key;
$prev_value = $value;
}