key_variation3.phpt 997 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. Test key() function : usage variations
  3. --FILE--
  4. <?php
  5. /* Prototype : mixed key(array $array_arg)
  6. * Description: Return the key of the element currently pointed to by the internal array pointer
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Test how the internal pointer is affected when two variables are referenced to each other
  11. */
  12. echo "*** Testing key() : usage variations ***\n";
  13. $array1 = array ('zero', 'one', 'two');
  14. echo "\n-- Initial position of internal pointer --\n";
  15. var_dump(key($array1));
  16. // Test that when two variables are referenced to one another
  17. // the internal pointer is the same for both
  18. $array2 = &$array1;
  19. next($array1);
  20. echo "\n-- Position after calling next() --\n";
  21. echo "\$array1: ";
  22. var_dump(key($array1));
  23. echo "\$array2: ";
  24. var_dump(key($array2));
  25. ?>
  26. ===DONE===
  27. --EXPECTF--
  28. *** Testing key() : usage variations ***
  29. -- Initial position of internal pointer --
  30. int(0)
  31. -- Position after calling next() --
  32. $array1: int(1)
  33. $array2: int(1)
  34. ===DONE===