.01 .02 .03 .04 | <?php $array = array( 1, 1, 2, 3, 5, 8, 13 ); ?> |
.01 .02 .03 .04 .05 | <?php foreach( $array as $value ) echo $value . '<br />'; ?> |
.01 .02 .03 .04 | <?php $array = array( 'premier' => 'N° 1', 'deuxieme' => 'N° 2', 'troisieme' => 'N° 3'); ?> |
.01 .02 .03 .04 .05 .06 .07 .08 .09 .10 .11 .12 | <?php $array = array( 'premier' => 'N° 1', 'deuxieme' => 'N° 2', 'troisieme' => 'N° 3'); foreach( $array as $value ) // on parcourt $array, la valeur de l'item courant est copiée dans $value echo $value . '<br />'; // affichage ?> Affiche: N° 1 N° 2 N° 3 |
.01 .02 .03 .04 .05 .06 .07 | <?php $array = array( 'premier' => 'N° 1', 'deuxieme' => 'N° 2', 'troisieme' => 'N° 3'); foreach( $array as $key => $value ) echo 'Cet élément a pour clé "' . $key . '" et pour valeur "' . $value . '"<br />'; ?> |
.01 .02 .03 .04 .05 .06 .07 .08 .09 .10 .11 .12 .13 .14 .15 | <?php foreach( $_SERVER as $key => $value ) echo '$_SERVER['' . $key . ''] =' . $value . '<br />'; ?> Affiche: $_SERVER['HTTP_HOST'] =localhost $_SERVER['HTTP_USER_AGENT'] =Mozilla/5.0 (Windows; U; Windows NT 5.0; fr; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1 $_SERVER['HTTP_ACCEPT'] =text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 $_SERVER['HTTP_ACCEPT_LANGUAGE'] =fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3 $_SERVER['HTTP_ACCEPT_ENCODING'] =gzip,deflate $_SERVER['HTTP_ACCEPT_CHARSET'] =ISO-8859-1,utf-8;q=0.7,*;q=0.7 $_SERVER['HTTP_KEEP_ALIVE'] =300 ... |
.01 .02 .03 .04 .05 .06 .07 .08 .09 .10 .11 .12 .13 .14 .15 .16 .17 .18 .19 .20 .21 .22 .23 .24 .25 .26 .27 .28 .29 .30 .31 | <?php $array = array( 'fruits' => array( 'pommes', 'tomates', 'abricots' ), 'animaux' => array( 'chats', 'chiens' ), 'pays' => array( 'Suisse', 'France', 'Angleterre' ) ); foreach( $array as $key => $value ) { echo $key . ': <br />'; foreach( $value as $valeur ) echo ' ' . $valeur . '<br />'; echo '<br />'; } ?> Affiche: fruits: pommes tomates abricots animaux: chats chiens pays: Suisse France Angleterre |