How to use next in PHP

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

next() function in PHP

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

Syntax

next(array)

Parameter

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

Example

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

<html>

<body>

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

    <?php 

    $subject_list = array('Language', 'Math', 'Science', 'Geography'); 

    $subject = current($subject_list); 

    echo "Current value : $subject <br />"; 

    $subject = next($subject_list); 

    echo "next value : $subject <br />"; 

    $subject = next($subject_list); 

    echo "next value : $subject <br />"; 

    $subject= prev($subject_list); 

    echo "prev value : $subject <br />"; 

    $subject= end($subject_list); 

    echo "end value : $subject <br />"; 

    ?> 

</body>

</html>

 

Output

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