A quick way to iterate an array using the Key,value,current,next and prev functions in PHP

Source: Internet
Author: User
This article mainly introduces the method of using Key,value,current,next and prev function to iterate the array in PHP, analyzes the common technique and example usage of array traversal in PHP, and the friends who need can refer to the following

The examples in this article describe how to iterate an array using the Key,value,current,next and prev functions in PHP. Share to everyone for your reference. The specific analysis is as follows:

There are a series of functions for array traversal in PHP that allow us to manipulate arrays very conveniently, and the first step is to move the pointer to the beginning of the array, using the Reset () function.

Use the Prev () and Next () functions to view the previous and next elements of an array. The current () function can be used to obtain the value of the key () using the key () function.

$array = Array (' foo ' = ' bar ', ' baz ', ' bat ' = 2), function Displayarray (& $array) {Reset ($array), while (Key ($arr ay) {!== null) {echo key ($array). ":". Current ($array). Php_eol;next ($array);}}

I hope this article is helpful to everyone's PHP programming.

  • 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.