私は非常によく似た問題を抱えていて、すべての検索が私をここに導きました。誰かが私の投稿がお役に立てば幸いです。私自身のコードから:PHP 5.3.0の場合、これは機能しました:
foreach ($aMainArr as $aCurrentEntry) {
$nextElm = current($aMainArr); //the 'current' element is already one element ahead of the already fetched but this happens just one time!
if ($nextElm) {
$nextRef = $nextElm['the_appropriate_key'];
next($aMainArr); //then you MUST continue using next, otherwise you stick!
} else { //caters for the last element
further code here...
}
//further code here which processes $aMainArr one entry at a time...
}
PHP 7.0.19の場合、以下が機能しました。
reset($aMainArr);
foreach ($aMainArr as $aCurrentEntry) {
$nextElm = next($aMainArr);
if ($nextElm) {
$nextRef = $nextElm['the_appropriate_key'];
} else { //caters for the last element
further code here...
}
//further code here which processes $aMainArr one entry at a time...
}