Copy CodeThe code is as follows:
A
$arr =array (' a ' = ' = ' abc ', ' B ' =>123, ' C ' =>true);
B
$arr =range (' A ', ' d ');
1
for ($i =0; $i
echo $arr [$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 '
';
?>
Use statement a $arr =array (' a ' = ' = ' abc ', ' B ' =>123, ' C ' =>true); Initialize the $arr to get a numeric index array, output as follows:
, , ,
ABC, 123, 1,
A-ABC, b-123, C-1,
A-ABC, b-123, C-1,
A-ABC, b-123, c-1, using statement b $arr =range (' A ', ' d '); Initialize the $arr to get an associative array, the output is as follows:
A, B, C, D,
A, B, C, D,
0-a, 1-b, 2-c,
0-a, 1-b, 2-c,
0-a, 1-b, 2-c, D, the For loop is limited to numeric indexes only, and the for and foreach traversal does not require the reset () operation to be performed for the next iteration, and each method is required.
The above describes the LED lights and energy-saving lamps compared to PHP several single-dimension array traversal method comparison, including LED lights and energy-saving lamp comparison of content, I hope that the PHP tutorial interested in a friend helpful.