reset_variation3.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --TEST--
  2. Test reset() function : usage variations - Referenced variables
  3. --FILE--
  4. <?php
  5. /* Prototype : mixed reset(array $array_arg)
  6. * Description: Set array argument's internal pointer to the first element and return it
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Reference two arrays to each other then call reset() to test position of
  11. * internal pointer in both arrays
  12. */
  13. echo "*** Testing reset() : usage variations ***\n";
  14. $array1 = array ('zero', 'one', 'two');
  15. echo "\n-- Initial position of internal pointer --\n";
  16. var_dump(current($array1));
  17. // Test that when two variables are referenced to one another
  18. // the internal pointer is the same for both
  19. $array2 = &$array1;
  20. next($array1);
  21. echo "\n-- Position after calling next() --\n";
  22. echo "\$array1: ";
  23. var_dump(current($array1));
  24. echo "\$array2: ";
  25. var_dump(current($array2));
  26. echo "\n-- Position after calling reset() --\n";
  27. var_dump(reset($array1));
  28. echo "\$array1: ";
  29. var_dump(current($array1));
  30. echo "\$array2: ";
  31. var_dump(current($array2));
  32. ?>
  33. ===DONE===
  34. --EXPECTF--
  35. *** Testing reset() : usage variations ***
  36. -- Initial position of internal pointer --
  37. string(4) "zero"
  38. -- Position after calling next() --
  39. $array1: string(3) "one"
  40. $array2: string(3) "one"
  41. -- Position after calling reset() --
  42. string(4) "zero"
  43. $array1: string(4) "zero"
  44. $array2: string(4) "zero"
  45. ===DONE===