each_basic.phpt 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. array(4) {
  41. [1]=>
  42. int(1)
  43. ["value"]=>
  44. int(1)
  45. [0]=>
  46. string(3) "one"
  47. ["key"]=>
  48. string(3) "one"
  49. }
  50. -- End position: --
  51. array(4) {
  52. [1]=>
  53. string(6) "twenty"
  54. ["value"]=>
  55. string(6) "twenty"
  56. [0]=>
  57. int(20)
  58. ["key"]=>
  59. int(20)
  60. }
  61. -- Passed the end of array: --
  62. bool(false)
  63. Done