Use the pointer function to traverse the following arrays:
$arr = $arr =[1, ' =>true,24=> ' Harry Potter ', ' ' = ' and ' JavaScript ', ' class ' = ' English '];
Reference:
Task
1. Output array
2. Iterate through the array before
3. Traversing the array from the back forward
<?PHP//Defining Arrays$arr=[1, ' ' = =true,24=> ' Harry Potter ', ' ' + ' javascript ', ' class ' = ' 中文版 '];//which output function does the output array use? Echo' <pre> '; Print_r($arr);Echo' </pre> ';//iterating through an array from the GO//First step: Resetting the array pointer (moves the array pointer to the beginning of the array)Reset($arr);//Step Two: Traversing the key names and key values of each element through the movement of the array pointer while( Current($arr)){ Echo' The key name at the current pointer location is: '.Key($arr).‘ <br> '; Echo' The key value at the current pointer location is: '. Current($arr).‘ <br> '; //move the pointer backwards Next($arr);}Echo' ;//iterate through the array from the back forward (the steps are similar to the previous traversal of the array, and the small partner tries it out by himself)//pointer to the last positionEnd($arr); while( Current($arr)){ Echo' The key name at the current pointer location is: '.Key($arr).‘ <br> '; Echo' The key value at the current pointer location is: '. Current($arr).‘ <br> '; //move the pointer forward prev($arr);}Echo' ;?>
Array using _1-20 programming exercises