This article introduces the method of obtaining the current array value of the PHP array, and friends in need can refer to it.
In PHP array operations, you can use the current() function to return the array value at the current pointer position in the array. The form is as follows: mixed current(array array) Example, get array value: <?php $fruits = array("apple"=>"red", "banana"=>"yellow"); while ($fruit = current($fruits)) { printf("%s <br />", $fruit); next($fruits); } // by bbs.it-home.org // red // yellow ?> Copy after login About the definition and usage of current function. Definition and usage The current() function returns the current element (cell) in the array. Each array has an internal pointer that points to its "current" element, initially pointing to the first element inserted into the array. The current() function returns the value of the array element currently pointed to by the internal pointer without moving the pointer. If the internal pointer points beyond the end of the cell list, current() returns FALSE. Grammar current(array) Parameter Description array required. Specifies the array to use. Tips and Notes Note: This function also returns FALSE if there are empty elements, or if the element has no value. Tip: This function does not move the internal pointer. To do this, use the next() and prev() functions. Example: <?php $people = array("Peter", "Joe", "Glenn", "Cleveland"); echo current($people) . "<br />"; //by bbs.it-home.org ?> Copy after login Output result: Peter That’s all about using current() to obtain the current value of an array. I hope it can help everyone. |