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.