1--TEST--
2Test 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/*
11 * Test how key() behaves with muti-dimensional and recursive arrays
12 */
13
14echo "*** Testing key() : usage variations ***\n";
15
16echo "\n-- Two Dimensional Array --\n";
17$multi_array = array ('zero', array (1, 2, 3), 'two');
18echo "Initial Position: ";
19var_dump(key($multi_array));
20
21echo "Next Position:    ";
22next($multi_array);
23var_dump(key($multi_array));
24
25echo "End Position:     ";
26end($multi_array);
27var_dump(key($multi_array));
28
29echo "\n-- Access an Array Within an Array --\n";
30//accessing an array within an array
31echo "Initial Position: ";
32var_dump(key($multi_array[1]));
33
34echo "\n-- Recursive, Multidimensional Array --\n";
35//create a recursive array
36$multi_array[] = &$multi_array;
37
38//See where internal pointer is after adding more elements
39echo "Current Position: ";
40var_dump(key($multi_array));
41
42//see if internal pointer is in same position as referenced array
43var_dump(key($multi_array[3][3][3]));
44// see if internal pointer is in the same position from when accessing this inner array
45var_dump(key($multi_array[3][3][3][1]));
46?>
47===DONE===
48--EXPECT--
49*** Testing key() : usage variations ***
50
51-- Two Dimensional Array --
52Initial Position: int(0)
53Next Position:    int(1)
54End Position:     int(2)
55
56-- Access an Array Within an Array --
57Initial Position: int(0)
58
59-- Recursive, Multidimensional Array --
60Current Position: int(2)
61int(2)
62int(0)
63===DONE===
64