/* foreach example 1: value only * / $a = array (1, 2, 3, 17); foreach ($a as $v) {print "Current value of \$a: $v.\n";} / * foreach example 2: value (with key printed for illustration) * / $a = array (1, 2, 3, 17); $i = 0; / * for illustrative purposes only * / foreach($a as $v) {print "\$a[$i] = $v.\n"; $i++;} / * foreach example 3: key and value * / $a = array ("one "= 1, "two" = 2, "three "= 3, "seventeen" = 17); foreach($a as $k = $v) {print "\$a[$k] = $v.\n";} / * foreach example 4: multi-dimensional arrays * / $a[0][0] = "a"; $a[0][1] = "b"; $a[1][0] = "y"; $a[1][1] = "z"; foreach($a as $v1) {foreach ($v1 as $v2) {print "$v2\n";}} / * foreach example 5: dynamic arrays * / foreach(array(1, 2, 3, 4, 5) as $v) {print "$v\n";}
?php / * exemple 1: valeurs seules * / $a = array (1, 2, 3, 17); foreach ($a as $v) {print "Valeur courante de \$a: $v.\n";} / * exemple 2: valeurs (avec la cl eacute; correspondante) * / $a = array (1, 2, 3, 17); $i = 0; / * pour l'illustration uniquement * / foreach($a as $v) {print "\$a[$i] = $v.\n";} / * exemple 3: cl eacute; et valeur * / $a = array ("un "= 1, "deux" = 2, "trois "= 3, "dix-sept" = 17); foreach($a as $k = $v) {print "\$a[$k] = $v.\n";} / * exemple 4: tableaux multi-dimensionnels * / $a[0][0] = "a"; $a[0][1] = "b"; $a[1][0] = "y"; $a[1][1] = "z"; foreach($a as $v1) {foreach ($v1 as $v2) {print "$v2\n";}} / * exemple 5: tableaux dynamique * / foreach(array(1, 2, 3, 4, 5) as $v) {print "$v\n";}?