php uses the "current()" function to output the current element of the array; the current() function can return the current element of the array, and the syntax is "current($array)". In PHP, each array has an internal pointer pointing to its "current" unit (element); and through the current() function, you can get the value of the array element pointed to by the current internal pointer.
The operating environment of this tutorial: windows7 system, PHP version 8.1, DELL G3 computer
php output array current Elements use the "current()" function.
In PHP, each array has an internal pointer pointing to its "current" unit (element). This pointer initially points to the first unit in the current array.
Through the current() function, you can get the value of the element pointed to by the internal pointer. Its syntax format is as follows:
current($array)
The parameter $array represents the array being operated on.
current() function can return the value of the array element pointed to by the current internal pointer, but it does not move the pointer. If you need to move the pointer, you need to use it in conjunction with other functions; if the internal The pointer points beyond the end of the array, and the current() function returns FALSE.
Example: Use the current() function to output the current element of the array
<?php header('content-type:text/html;charset=utf-8'); $array = array( 'PHP中文网', '//m.sbmmt.com/', 'current() 函数' ); echo current($array).'<br>'; echo pos($array).'<br>'; next($array); echo current($array).'<br>'; next($array); next($array); var_dump(current($array)); ?>
In the above example code we used the next() function, its function is the same as The current() function is similar, but it can move the internal pointer down to the next element of the array. You can learn about it here.
In PHP, there are many functions similar to the current() function that can operate the internal pointers of the array, as follows:
end(): end the internal pointer Points to the last element in the array;
next(): Points the internal pointer to the next element in the array;
prev() : Point the internal pointer to the previous element in the array;
reset(): Point the internal pointer to the first element in the array;
each(): Returns the key name and key value of the current element, and points the internal pointer to the next element in the array.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What function does php use to output the current element of an array?. For more information, please follow other related articles on the PHP Chinese website!