prev_basic.phpt 983 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. --TEST--
  2. Test prev() function : basic functionality
  3. --FILE--
  4. <?php
  5. /*
  6. * Test basic functionality of prev()
  7. */
  8. echo "*** Testing prev() : basic functionality ***\n";
  9. $array = array('zero', 'one', 'two');
  10. end($array);
  11. echo key($array) . " => " . current($array) . "\n";
  12. var_dump(prev($array));
  13. echo key($array) . " => " . current($array) . "\n";
  14. var_dump(prev($array));
  15. echo key($array) . " => " . current($array) . "\n";
  16. var_dump(prev($array));
  17. echo "\n*** Testing an array with differing values/keys ***\n";
  18. $array2 = array('one', 2 => "help", 3, false, 'stringkey2' => 'val2', 'stringkey1' => 'val1');
  19. end($array2);
  20. $length = count($array2);
  21. for ($i = $length; $i > 0; $i--) {
  22. var_dump(prev($array2));
  23. }
  24. ?>
  25. --EXPECT--
  26. *** Testing prev() : basic functionality ***
  27. 2 => two
  28. string(3) "one"
  29. 1 => one
  30. string(4) "zero"
  31. 0 => zero
  32. bool(false)
  33. *** Testing an array with differing values/keys ***
  34. string(4) "val2"
  35. bool(false)
  36. int(3)
  37. string(4) "help"
  38. string(3) "one"
  39. bool(false)