Annotation of embedaddon/php/ext/standard/tests/array/array_values_variation3.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_values() function : usage variations - array keys different data types
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: /*
11: * Pass arrays where the keys are different data types as $input argument
12: * to array_values() to test behaviour
13: */
14:
15: echo "*** Testing array_values() : usage variations ***\n";
16:
17: //get an unset variable
18: $unset_var = 10;
19: unset ($unset_var);
20:
21: // heredoc string
22: $heredoc = <<<EOT
23: hello world
24: EOT;
25:
26: // unexpected values to be passed as $input
27: $inputs = array(
28:
29: // int data
30: /*1*/ 'int' => array(
31: 0 => 'zero',
32: 1 => 'one',
33: 12345 => 'positive',
34: -2345 => 'negative',
35: ),
36:
37: // float data
38: /*2*/ 'float' => array(
39: 10.5 => 'positive',
40: -10.5 => 'negative',
41: .5 => 'half',
42: ),
43:
44: /*3*/ 'extreme floats' => array(
45: 12.3456789000e10 => 'large',
46: 12.3456789000E-10 => 'small',
47: ),
48:
49: // null data
50: /*4*/ 'null uppercase' => array(
51: NULL => 'null 1',
52: ),
53:
54: /*5*/ 'null lowercase' => array(
55: null => 'null 2',
56: ),
57:
58: // boolean data
59: /*6*/ 'bool lowercase' => array(
60: true => 'lowert',
61: false => 'lowerf',
62: ),
63:
64: /*7*/ 'bool uppercase' => array(
65: TRUE => 'uppert',
66: FALSE => 'upperf',
67: ),
68:
69: // empty data
70: /*8*/ 'empty double quotes' => array(
71: "" => 'emptyd',
72: ),
73:
74: /*9*/ 'empty single quotes' => array(
75: '' => 'emptys',
76: ),
77:
78: // string data
79: /*10*/ 'string' => array(
80: "stringd" => 'stringd',
81: 'strings' => 'strings',
82: $heredoc => 'stringh',
83: ),
84:
85: // undefined data
86: /*11*/ 'undefined' => array(
87: @$undefined_var => 'undefined',
88: ),
89:
90: // unset data
91: /*12*/ 'unset' => array(
92: @$unset_var => 'unset',
93: ),
94: );
95:
96: // loop through each element of $inputs to check the behavior of array_values()
97: $iterator = 1;
98: foreach($inputs as $key => $input) {
99: echo "\n-- Iteration $iterator: $key data --\n";
100: var_dump( array_values($input) );
101: $iterator++;
102: };
103: echo "Done";
104: ?>
105:
106: --EXPECTF--
107: *** Testing array_values() : usage variations ***
108:
109: -- Iteration 1: int data --
110: array(4) {
111: [0]=>
112: string(4) "zero"
113: [1]=>
114: string(3) "one"
115: [2]=>
116: string(8) "positive"
117: [3]=>
118: string(8) "negative"
119: }
120:
121: -- Iteration 2: float data --
122: array(3) {
123: [0]=>
124: string(8) "positive"
125: [1]=>
126: string(8) "negative"
127: [2]=>
128: string(4) "half"
129: }
130:
131: -- Iteration 3: extreme floats data --
132: array(2) {
133: [0]=>
134: string(5) "large"
135: [1]=>
136: string(5) "small"
137: }
138:
139: -- Iteration 4: null uppercase data --
140: array(1) {
141: [0]=>
142: string(6) "null 1"
143: }
144:
145: -- Iteration 5: null lowercase data --
146: array(1) {
147: [0]=>
148: string(6) "null 2"
149: }
150:
151: -- Iteration 6: bool lowercase data --
152: array(2) {
153: [0]=>
154: string(6) "lowert"
155: [1]=>
156: string(6) "lowerf"
157: }
158:
159: -- Iteration 7: bool uppercase data --
160: array(2) {
161: [0]=>
162: string(6) "uppert"
163: [1]=>
164: string(6) "upperf"
165: }
166:
167: -- Iteration 8: empty double quotes data --
168: array(1) {
169: [0]=>
170: string(6) "emptyd"
171: }
172:
173: -- Iteration 9: empty single quotes data --
174: array(1) {
175: [0]=>
176: string(6) "emptys"
177: }
178:
179: -- Iteration 10: string data --
180: array(3) {
181: [0]=>
182: string(7) "stringd"
183: [1]=>
184: string(7) "strings"
185: [2]=>
186: string(7) "stringh"
187: }
188:
189: -- Iteration 11: undefined data --
190: array(1) {
191: [0]=>
192: string(9) "undefined"
193: }
194:
195: -- Iteration 12: unset data --
196: array(1) {
197: [0]=>
198: string(5) "unset"
199: }
200: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>