How can I do the foreach correctly [closed]

-4

asked by anonymous 28.12.2016 / 15:56

1 answer

2

I did not find any foreach in the code I show, but according to the link

A foreach would be like this, the first example is given the array index value for the $ key variable.

and the second example separates the value of the array into two variables, one for the key and another for the value, being accessible by this variables during foreach execution.

Note: Variables do not exist outside the foreach.

$dia = array('25' => 'Domingo','26' => 'Segunda','27' => 'Terça','28' => 'Quarta');

foreach ($dia as $key){
    echo 'Hoje é dia '.$key;
}

foreach ($dia as $key => $value){
    echo 'Hoje é dia '. $key. ' que caiu no '.$value;
}
    
28.12.2016 / 18:29