Annotation of embedaddon/php/ext/standard/tests/array/current_variation4.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test current() function : usage variations - multi-dimensional arrays
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: /*
12: * Test how current() behaves with muti-dimensional and recursive arrays
13: */
14:
15: echo "*** Testing current() : usage variations ***\n";
16:
17: echo "\n-- Two Dimensional Array --\n";
18: $multi_array = array ('zero', array (1, 2, 3), 'two');
19: echo "Initial Position: ";
20: var_dump(current($multi_array));
21:
22: echo "Next Position: ";
23: next($multi_array);
24: var_dump(current($multi_array));
25:
26: echo "End Position: ";
27: end($multi_array);
28: var_dump(current($multi_array));
29:
30: echo "\n-- Access an Array Within an Array --\n";
31: //accessing an array within an array
32: echo "Initial Position: ";
33: var_dump(current($multi_array[1]));
34:
35: echo "\n-- Recursive, Multidimensional Array --\n";
36: //create a recursive array
37: $multi_array[] = &$multi_array;
38:
39: //See where internal pointer is after adding more elements
40: echo "Current Position: ";
41: var_dump(current($multi_array));
42:
43: //see if internal pointer is in same position as referenced array
44: var_dump(current($multi_array[3][3][3]));
45: // see if internal pointer is in the same position from when accessing this inner array
46: var_dump(current($multi_array[3][3][3][1]));
47: ?>
48: ===DONE===
49: --EXPECTF--
50: *** Testing current() : usage variations ***
51:
52: -- Two Dimensional Array --
53: Initial Position: string(4) "zero"
54: Next Position: array(3) {
55: [0]=>
56: int(1)
57: [1]=>
58: int(2)
59: [2]=>
60: int(3)
61: }
62: End Position: string(3) "two"
63:
64: -- Access an Array Within an Array --
65: Initial Position: int(1)
66:
67: -- Recursive, Multidimensional Array --
68: Current Position: string(3) "two"
69: string(3) "two"
70: int(1)
71: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>