array_values_variation6.phpt 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --TEST--
  2. Test array_values() function : usage variations - Referenced variables
  3. --FILE--
  4. <?php
  5. /* Prototype : array array_values(array $input)
  6. * Description: Return just the values from the input array
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Test array_values() when:
  11. * 1. Passed an array made up of referenced variables
  12. * 2. Passed an array by reference
  13. */
  14. echo "*** Testing array_values() : usage variations ***\n";
  15. $val1 = 'one';
  16. $val2 = 'two';
  17. $val3 = 'three';
  18. echo "\n-- \$input is an array made up of referenced variables: --\n";
  19. $input = array(&$val1, &$val2, &$val3);
  20. var_dump($result1 = array_values($input));
  21. echo "Change \$val2 and check result of array_values():\n";
  22. $val2 = 'deux';
  23. var_dump($result1);
  24. echo "Done";
  25. ?>
  26. --EXPECTF--
  27. *** Testing array_values() : usage variations ***
  28. -- $input is an array made up of referenced variables: --
  29. array(3) {
  30. [0]=>
  31. &string(3) "one"
  32. [1]=>
  33. &string(3) "two"
  34. [2]=>
  35. &string(5) "three"
  36. }
  37. Change $val2 and check result of array_values():
  38. array(3) {
  39. [0]=>
  40. &string(3) "one"
  41. [1]=>
  42. &string(4) "deux"
  43. [2]=>
  44. &string(5) "three"
  45. }
  46. Done