$arr=array('key1'=>'val','key2'=>'another','another'=>'more stuff');foreach($arras$key=>$val){//do stuff}//or alt syntaxforeach($arras$key=>$val)://do stuff here as wellendforeach;
$myArray=[1,2,3];foreach($myArrayas$item){echo$item;}$myAssocArray=[1=>'One',2=>'Two',3=>'Three'];foreach($myAssocArrayas$key=>$value){echo$key.' is '.$value;}
<?php$array=[[1,2],[3,4],];foreach($arrayaslist($a,$b)){// $a contains the first element of the nested array,// and $b contains the second element.echo"A: $a; B: $b
";}?>
<?php$arr=array(1,2,3,4);foreach($arras&$value){$value=$value*2;}// $arr is now array(2, 4, 6, 8)unset($value);// break the reference with the last element?>