How to use reset in PHP

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

reset() function in PHP

  • The reset() function is used to move the internal pointer to the first element of the array.
  • The reset() function returns the value of the first element in the array on success, or FALSE on failure..
  • The reset() function returns FALSE on failure case.




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


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



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


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

    $subject = current($subject_array);

    print "Current subject : $subject <br />";

    $subject = next($subject_array); 

    print "Next subject : $subject <br />";

    $subject = current($subject_array);

    print "Current subject : $subject <br />";

    $subject = prev($subject_array); 

    print "previous subject : $subject <br />";

    $subject = end($subject_array);  

    print "End subject : $subject <br />";

    $subject = reset($subject_array);  

    print "reset subjects : $subject <br />";

    $subject = current($subject_array);

    print "Current subject : $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.