key_variation3.phpt 790 B

123456789101112131415161718192021222324252627282930313233343536
  1. --TEST--
  2. Test key() function : usage variations
  3. --FILE--
  4. <?php
  5. /*
  6. * Test how the internal pointer is affected when two variables are referenced to each other
  7. */
  8. echo "*** Testing key() : usage variations ***\n";
  9. $array1 = array ('zero', 'one', 'two');
  10. echo "\n-- Initial position of internal pointer --\n";
  11. var_dump(key($array1));
  12. // Test that when two variables are referenced to one another
  13. // the internal pointer is the same for both
  14. $array2 = &$array1;
  15. next($array1);
  16. echo "\n-- Position after calling next() --\n";
  17. echo "\$array1: ";
  18. var_dump(key($array1));
  19. echo "\$array2: ";
  20. var_dump(key($array2));
  21. ?>
  22. --EXPECT--
  23. *** Testing key() : usage variations ***
  24. -- Initial position of internal pointer --
  25. int(0)
  26. -- Position after calling next() --
  27. $array1: int(1)
  28. $array2: int(1)