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.