Copy code The code is as follows:
//a
$arr=array('a'=>'abc','b'=>123,'c'=> ;true);
//b
//$arr=range('a','d');
//1
for($i=0;$i
echo '
';
//2
foreach($arr as $key)
echo "$key, ";
echo '
';
//3
foreach($arr as $key=>$val)
echo "$key-$val, ";
echo '
';
//4
reset($arr);
while($item=each($arr)){
echo $item['key'].'-'.$item['value'].', ';
}
echo '
';
//5
reset($arr);
while(list($key,$val)=each($arr)){
echo "$key-$val, ";
}
echo '
';
?>
The above introduces the comparison between LED lamps and energy-saving lamps and the comparison of several single-dimensional array traversal methods in PHP, including the comparison between LED lamps and energy-saving lamps. I hope it will be helpful to friends who are interested in PHP tutorials.