“pavé” Réponses codées

php foreach

<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

foreach($age as $x => $val) {
  echo "$x = $val<br>";
}
?>
Mohammadali Mirhamed

foreach en php

$arr = array(
	'key1' => 'val',
	'key2' => 'another',
	'another' => 'more stuff' 
);
foreach ($arr as $key => $val){
	//do stuff
}

//or alt syntax
foreach ($arr as $key => $val) :
   //do stuff here as well
endforeach;
Brainy Bison

PHP OFREACH


<?php

$a = array(1, 2, 3, 17);

foreach ($a as $index => $v) {
    echo "Current value of \$a: $v.\n";
}

?>

Alberto Peripolli

pavé


<?php
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
    $value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
unset($value); // break the reference with the last element
?>

Troubled Termite

Réponses similaires à “pavé”

Questions similaires à “pavé”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code