配列を for で繰り返し。
$array = array('a' , 'b' , 'c' , 'd'); for($i=0;$i配列を foreach で繰り返し。
$array = array('a' , 'b' , 'c' , 'd'); foreach ($array as $arrayValue){ echo $arrayValue; }連想配列を foreach で繰り返し。
$array = array('1at'=>'a' , '2nd'=>'b' , '3rd'=>'c' , '4th'=>'d'); foreach ($array as $arrayKey => $arrayValue){ echo "['$arrayKey'] = $arrayValue"; }
ループの中で、連想配列の中身を書き換え。
$array = array('1at'=>'a' , '2nd'=>'b' , '3rd'=>'c' , '4th'=>'d'); foreach ($array as $arrayKey => &$arrayValue){ $arrayValue = "[$arrayValue]"; echo "['$arrayKey'] = $arrayValue"; } unset($arrayValue);//参照を解除