How to use prev in PHP

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

prev() function in PHP

  • The prev() function is used to move the internal pointer to, and outputs, the previous element in the array.
  • The prev() function returns the value of the previous element in the array on success.
  • The prev() function returns FALSE if there are no more element.

Syntax

prev(array)

Parameter

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

Example

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

<html>

<body>

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

    <?php

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

    $subject = current($subject_list);

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

    $subject = next($subject_list); 

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

    $subject = current($subject_list);

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

    $subject = prev($subject_list); 

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

    $subject = end($subject_list);  

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

    $subject = prev($subject_list);

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

    ?>

</body>

</html>

 

Output

prevphp.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.