each_variation6.phpt 994 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. --TEST--
  2. Test each() function : usage variations - Internal array pointer
  3. --FILE--
  4. <?php
  5. /* Prototype : array each(array $arr)
  6. * Description: Return the currently pointed key..value pair in the passed array,
  7. * and advance the pointer to the next element
  8. * Source code: Zend/zend_builtin_functions.c
  9. */
  10. /*
  11. * Test the position of the internal array pointer after a call to each()
  12. */
  13. echo "*** Testing each() : usage variations ***\n";
  14. $arr = array('zero', 'one', 'two', 'abc', 'xyz');
  15. echo "\n-- Current position: --\n";
  16. echo key($arr) . " => " . current($arr) . "\n";
  17. echo "\n-- Call to each(): --\n";
  18. var_dump( each($arr) );
  19. echo "\n-- New position: --\n";
  20. echo key($arr) . " => " . current($arr) . "\n";
  21. echo "Done";
  22. ?>
  23. --EXPECTF--
  24. *** Testing each() : usage variations ***
  25. -- Current position: --
  26. 0 => zero
  27. -- Call to each(): --
  28. array(4) {
  29. [1]=>
  30. string(4) "zero"
  31. ["value"]=>
  32. string(4) "zero"
  33. [0]=>
  34. int(0)
  35. ["key"]=>
  36. int(0)
  37. }
  38. -- New position: --
  39. 1 => one
  40. Done