Array using _1-20 programming exercises

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.