Annotation of embedaddon/php/ext/standard/tests/array/array_shift_variation6.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_shift() function : usage variations - Referenced arrays
3: --FILE--
4: <?php
5: /* Prototype : mixed array_shift(array &$stack)
6: * Description: Pops an element off the beginning of the array
7: * Source code: ext/standard/array.c
8: */
9:
10: /*
11: * Test how array_shift when passed:
12: * 1. a variable that is referenced to an array
13: * 2. an array that contains a referenced array
14: */
15:
16: echo "*** Testing array_shift() : usage variations ***\n";
17:
18: echo "\n-- Variable is referenced array --\n";
19: $original_array = array('zero', 'one', 'two');
20: $copied_array = &$original_array;
21:
22: echo "Result: ";
23: var_dump(array_shift($copied_array));
24: echo "\n\$original_array:\n";
25: var_dump($original_array);
26: echo "\n\$copied_array:\n";
27: var_dump($copied_array);
28:
29: echo "\n-- Element is referenced array --\n";
30: $new_array = array (&$copied_array, 1, 'two');
31: echo "Result: ";
32: var_dump(array_shift($new_array[0]));
33: echo "\n\$new_array:\n";
34: var_dump($new_array);
35: echo "\n\$copied_array\n";
36: var_dump($copied_array);
37:
38: echo "Done";
39: ?>
40: --EXPECTF--
41: *** Testing array_shift() : usage variations ***
42:
43: -- Variable is referenced array --
44: Result: string(4) "zero"
45:
46: $original_array:
47: array(2) {
48: [0]=>
49: string(3) "one"
50: [1]=>
51: string(3) "two"
52: }
53:
54: $copied_array:
55: array(2) {
56: [0]=>
57: string(3) "one"
58: [1]=>
59: string(3) "two"
60: }
61:
62: -- Element is referenced array --
63: Result: string(3) "one"
64:
65: $new_array:
66: array(3) {
67: [0]=>
68: &array(1) {
69: [0]=>
70: string(3) "two"
71: }
72: [1]=>
73: int(1)
74: [2]=>
75: string(3) "two"
76: }
77:
78: $copied_array
79: array(1) {
80: [0]=>
81: string(3) "two"
82: }
83: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>