Use an array pointer to traverse the array, FOR/FOREACH to traverse the array, and foreach
1. traverse one-dimensional arrays with array pointers
<? Phpheader ("Content-type: text/html; charset = UTF-8");/* use an array pointer to traverse the value of an array */$ arr = array ('A ', 'B', 'C', 'D'); echo current ($ arr); // returns the value of the current Unit of the pointer echo next ($ arr ); // The pointer moves to the next unit echo prev ($ arr); // the pointer moves to the previous unit and returns the value of the unit echo end ($ arr ); // move the pointer to the last unit echo reset ($ arr); // reset the Array (move the pointer to the beginning of the array) for ($ I = 0; $ I <count ($ arr ); $ I ++) {echo current ($ arr); // output the unit value of the current pointer a next ($ arr); // move the pointer down, output unit value}
2. FOR traversing two-dimensional arrays
$arr = array( 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 traverses two Arrays
$ Arr = array ('A', 'B', 'C', 'D'), array ('E', 'F', 'G ', 'H'), array ('I', 'J', 'k', 'l', 'M', 'n', '0 '),); foreach ($ arr as $ key = >$ value) {foreach ($ arr [$ key] as $ subkey => $ subval) {// here, the first array parameter foreach uses $ arr [$ key] to represent the second-dimensional array echo $ subval. ',';}}