Home > OS >  list a loop in ascending order with foreach (1 , 2 , 3 ...)
list a loop in ascending order with foreach (1 , 2 , 3 ...)

Time:10-21

some way to enumerate a loop in ascending order with foreach

<?php  
$semana=array("lunes","papa","miércoles","peras","viernes","sábado","domingo");
foreach ($semana as $dia) {
        echo $numero.','.$dia;
        }
?>

The result would be something like this:

1 , lunes
2 , papa
3 , miércoles
4 , peras

Thank you for your help

CodePudding user response:

Try this code

<?php 
$semana = array("lunes","papa","miércoles","peras","viernes","sábado","domingo.");
foreach ($semana as $numero => $dia) {
    echo ($numero   1) . ',' . $dia;
}
?>
  • Related