How to use current in PHP

In this article, I will explain how the current() function can be used in PHP.
  • 1475

current() function in PHP

  • The current() function is used to return the value of the current element in an array.
  • In current() function, every array has an internal pointer to its "current" element, which is initialized to the first element into the array.
  • The current() function returns FALSE on empty elements.




  • array array is required parameter. it is the input array.


The following example show to how the current() function can be used in PHP.



<h3 style="color: Red;">current() function example in PHP</h3>


    $subject_list = array('Hindi', 'English', 'Math', 'Science');

    $subject = current($subject_list);

    print "$subject <br />";

    $subject = next($subject_list); 

    print "$subject <br />";

    $subject = current($subject_list);

    print "$subject <br />";

    $subject = prev($subject_list); 

    print "$subject <br />";

    $subject = end($subject_list);  

    print "$subject <br />";

    $subject = current($subject_list);

    print "$subject <br />";







You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here


More Articles

© 2020 DotNetHeaven. All rights reserved.