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