each_basic.phpt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. --TEST--
  2. Test each() function : basic functionality
  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 basic functionality of each()
  12. */
  13. echo "*** Testing each() : basic functionality ***\n";
  14. $arr = array ('one' => 1, 'zero', 'two' => 'deux', 20 => 'twenty');
  15. echo "\n-- Passed array: --\n";
  16. var_dump($arr);
  17. echo "\n-- Initial position: --\n";
  18. var_dump(each($arr));
  19. echo "\n-- End position: --\n";
  20. end($arr);
  21. var_dump(each($arr));
  22. echo "\n-- Passed the end of array: --\n";
  23. var_dump(each($arr));
  24. echo "Done";
  25. ?>
  26. --EXPECTF--
  27. *** Testing each() : basic functionality ***
  28. -- Passed array: --
  29. array(4) {
  30. ["one"]=>
  31. int(1)
  32. [0]=>
  33. string(4) "zero"
  34. ["two"]=>
  35. string(4) "deux"
  36. [20]=>
  37. string(6) "twenty"
  38. }
  39. -- Initial position: --
  40. Deprecated: The each() function is deprecated. This message will be suppressed on further calls in %s on line %d
  41. array(4) {
  42. [1]=>
  43. int(1)
  44. ["value"]=>
  45. int(1)
  46. [0]=>
  47. string(3) "one"
  48. ["key"]=>
  49. string(3) "one"
  50. }
  51. -- End position: --
  52. array(4) {
  53. [1]=>
  54. string(6) "twenty"
  55. ["value"]=>
  56. string(6) "twenty"
  57. [0]=>
  58. int(20)
  59. ["key"]=>
  60. int(20)
  61. }
  62. -- Passed the end of array: --
  63. bool(false)
  64. Done