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.

Read the key of the current cursor position
$my_array=array("First One", "Second One", "Third One", "Fourth One", "Fifth One" );
echo key($my_array); // Output is 0 
$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()

$arr = array("apple", "banana", "cherry");
echo current($arr);  // Output: apple
next($arr);
echo current($arr);  // Output: banana
prev($arr);
echo current($arr);  // Output: apple

Example: Using current() with Multidimensional Arrays

$arr = array(
    array("name" => "John", "age" => 30),
    array("name" => "Jane", "age" => 25)
);
echo current($arr)["name"];  // Output: John
next($arr);
echo '<br>';
echo current($arr)["name"];  // Output: Jane
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()`.

Array REFERENCE
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer