current: to read the value of the array cursor position
We can read the value of the array element using current function.
echo current(array);
Example
$my_array=array("First One", "Second One", "Third One", "Fourth One", "Fifth One" );
echo current($my_array); // Output first one
current reads the value of the present internal pointer or cursor of the array. We can move the internal pointer to next element by using next
Example
$my_array=array("First One", "Second One", "Third One", "Fourth One");
echo current($my_array); // Output first one
next($my_array);
echo current($my_array);// Output Second One
Difference between each and current
By using each we can display the current element of the array but after displaying the internal pointer of the array shifts to next element. In case of current after returning the element the pointer does not move on its own and remains there.
$my_array=array("First One", "Second One", "Third One", "Fourth One", "Fifth One");
echo current($my_array); // Output : First One
echo next($my_array); // Output : Second One
echo next($my_array); // Output : Third One
echo prev($my_array); // Output : Second One
echo end($my_array); // Output : Fifth One
echo reset($my_array); // Output : First One
Example: Iterating Through Arrays with current(), next(), and prev()
Explanation: Iterating Arrays: Explains how `current()` can be combined with other pointer functions to move through arrays. Multidimensional Arrays: Shows how to handle complex arrays with `current()`. Reset vs Current: Highlights the difference between `current()` and `reset()`.