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

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com




    Post your comments , suggestion , error , requirements etc here .




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