1. Traversing a one-dimensional array with an array pointer
<?phpheader ("Content-type:text/html;charset=utf-8");/* Iterates over the value of an array with an array pointer */$arr = array (' A ', ' B ', ' C ', ' d '); echo Current ($arr); Returns the value of the current cell of the pointer echo next ($ARR); The pointer moves to the next unit, Echo prev ($arr); The pointer moves to the previous cell and returns the value of the cell Echo end ($arr); The pointer moves to the last unit, Echo Reset ($arr); Resets the array (the pointer moves to the beginning of the array) for ($i =0; $i <count ($arr); $i + +) { echo current ($arr); Outputs the cell value of the current pointer a next ($arr); Move the pointer down, output cell value}
2. For traversing a two-dimensional array
$arr = Array ( ' A ', ' B ', ' C ', ' d '), array (' E ', ' f ', ' g ', ' H '), array (' I ', ' j ', ' K ', ' l ', ' m ', ' n '), For ($i =0; $i <count ($arr), $i + +) { for ($j =0; $j <count ($arr [$i]), $j + +) echo $arr [$i] [$j]. ', '; }
3. Foreach traversal two-bit array
$arr = Array (Array (' A ', ' B ', ' C ', ' d '), Array (' E ', ' f ', ' g ', ' H '), a Rray (' I ', ' j ', ' K ', ' l ', ' m ', ' n ', ' 0 '), "foreach" ($arr as $key = + $value) {foreach ($arr [$key] as $subkey = = $subval) { The foreach first array parameter here uses $arr[$key] to represent the second-dimensional array in which echo $subval. ', '; }}