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