current_variation3.phpt 1.1 KB

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