<?php
$arr=[13,4,91,8];
foreach( $arr as $k=>$v){
if(end($arr)==$arr[$k]){
echo "This is the last value $v no pending value";
}
else {
echo "$v and next value is {$arr[$k+1]} <br>";
}
}
?>
----------------
<?php
$arr = [13, 4, 91, 8];
$lastIndex = count($arr) - 1;
foreach ($arr as $k => $v) {
if ($k === $lastIndex) {
echo "This is the last value $v, no pending value";
} else {
echo "$v and next value is {$arr[$k + 1]} <br>";
}
}
?>
13 and next value is 4
4 and next value is 91
91 and next value is 8
This is the last value 8, no pending value
No hay comentarios:
Publicar un comentario