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