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.

Syntax

reset(array)

Parameter

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

Example

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

<html>

<body>

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

    <?php

    $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 />";

?>

</body>

</html>

 

Output

resetphp.jpg
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
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.