each_variation4.phpt 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. --TEST--
  2. Test each() function : usage variations - Referenced variables
  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 behaviour of each() when:
  12. * 1. Passed an array made up of referenced variables
  13. * 2. Passed an array as $arr argument by reference
  14. */
  15. echo "*** Testing each() : usage variations ***\n";
  16. echo "\n-- Array made up of referenced variables: --\n";
  17. $val1 = 'foo';
  18. $val2 = 'bar';
  19. $arr1 = array('one' => &$val1, &$val2);
  20. echo "-- Call each until at the end of the array: --\n";
  21. var_dump( each($arr1) );
  22. var_dump( each($arr1) );
  23. var_dump( each($arr1) );
  24. echo "Done";
  25. ?>
  26. --EXPECTF--
  27. *** Testing each() : usage variations ***
  28. -- Array made up of referenced variables: --
  29. -- Call each until at the end of the array: --
  30. array(4) {
  31. [1]=>
  32. string(3) "foo"
  33. ["value"]=>
  34. string(3) "foo"
  35. [0]=>
  36. string(3) "one"
  37. ["key"]=>
  38. string(3) "one"
  39. }
  40. array(4) {
  41. [1]=>
  42. string(3) "bar"
  43. ["value"]=>
  44. string(3) "bar"
  45. [0]=>
  46. int(0)
  47. ["key"]=>
  48. int(0)
  49. }
  50. bool(false)
  51. Done