Using the key, value, current, next, and prev functions in php to traverse arrays _ php skills

Source: Internet
Author: User
This article mainly introduces how to use the key, value, current, next, and prev functions in php to traverse arrays. it gives a detailed analysis of common techniques and instance usage of array traversal in php, for more information about how to use the key, value, current, next, and prev functions in php to traverse arrays. Share it with you for your reference. The specific analysis is as follows:

Php has a series of functions for array traversal, which allows us to operate arrays very conveniently. to traverse an array, the first step is to point the pointer to the beginning of the array and use the reset () function.

You can use the prev () and next () functions to view the previous and next elements of the array. You can use the current () function to obtain the current value, and use the key () function to obtain the key value.

$ Array = array ('foo' => 'bar', 'Baz', 'bat' => 2); function displayArray (& $ array) {reset ($ array ); while (key ($ array )! = Null) {echo key ($ array). ":". current ($ array). PHP_EOL; next ($ array );}}

I hope this article will help you with php programming.

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.