A demonstration of all related methods:


SUBMITTED BY: henry1874w

DATE: June 26, 2017, 5:18 p.m.

FORMAT: Text only

SIZE: 849 Bytes

HITS: 772

  1. <?php
  2. $people = array("Peter", "Joe", "Glenn", "Cleveland");
  3. echo current($people) . "<br>"; // The current element is Peter
  4. echo next($people) . "<br>"; // The next element of Peter is Joe
  5. echo current($people) . "<br>"; // Now the current element is Joe
  6. echo prev($people) . "<br>"; // The previous element of Joe is Peter
  7. echo end($people) . "<br>"; // The last element is Cleveland
  8. echo prev($people) . "<br>"; // The previous element of Cleveland is Glenn
  9. echo current($people) . "<br>"; // Now the current element is Glenn
  10. echo reset($people) . "<br>"; // Moves the internal pointer to the first element of the array, which is Peter
  11. echo next($people) . "<br>"; // The next element of Peter is Joe
  12. print_r (each($people)); // Returns the key and value of the current element (now Joe), and moves the internal pointer forward
  13. ?>

comments powered by Disqus