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 // null data 33/*3*/ 'null uppercase' => array( 34 NULL => 'null 1', 35 ), 36 'null lowercase' => array( 37 null => 'null 2', 38 ), 39 40 // boolean data 41/*4*/ 'bool lowercase' => array( 42 true => 'lowert', 43 false => 'lowerf', 44 ), 45 'bool uppercase' => array( 46 TRUE => 'uppert', 47 FALSE => 'upperf', 48 ), 49 50 // empty data 51/*5*/ 'empty double quotes' => array( 52 "" => 'emptyd', 53 ), 54 'empty single quotes' => array( 55 '' => 'emptys', 56 ), 57 58 // string data 59/*6*/ 'string' => array( 60 "stringd" => 'stringd', 61 'strings' => 'strings', 62 $heredoc => 'stringh', 63 ), 64 65 // undefined data 66/*8*/ 'undefined' => array( 67 @$undefined_var => 'undefined', 68 ), 69 70 // unset data 71/*9*/ 'unset' => array( 72 @$unset_var => 'unset', 73 ), 74); 75 76// loop through each sub-array of $inputs to check the behavior of array_change_key_case() 77$iterator = 1; 78foreach($inputs as $key => $input) { 79 echo "\n-- Iteration $iterator : $key data --\n"; 80 var_dump( array_change_key_case($input, CASE_UPPER) ); 81 $iterator++; 82}; 83 84echo "Done"; 85?> 86--EXPECT-- 87*** Testing array_change_key_case() : usage variations *** 88 89-- Iteration 1 : int data -- 90array(4) { 91 [0]=> 92 string(4) "zero" 93 [1]=> 94 string(3) "one" 95 [12345]=> 96 string(8) "positive" 97 [-2345]=> 98 string(8) "negative" 99} 100 101-- Iteration 2 : null uppercase data -- 102array(1) { 103 [""]=> 104 string(6) "null 1" 105} 106 107-- Iteration 3 : null lowercase data -- 108array(1) { 109 [""]=> 110 string(6) "null 2" 111} 112 113-- Iteration 4 : bool lowercase data -- 114array(2) { 115 [1]=> 116 string(6) "lowert" 117 [0]=> 118 string(6) "lowerf" 119} 120 121-- Iteration 5 : bool uppercase data -- 122array(2) { 123 [1]=> 124 string(6) "uppert" 125 [0]=> 126 string(6) "upperf" 127} 128 129-- Iteration 6 : empty double quotes data -- 130array(1) { 131 [""]=> 132 string(6) "emptyd" 133} 134 135-- Iteration 7 : empty single quotes data -- 136array(1) { 137 [""]=> 138 string(6) "emptys" 139} 140 141-- Iteration 8 : string data -- 142array(3) { 143 ["STRINGD"]=> 144 string(7) "stringd" 145 ["STRINGS"]=> 146 string(7) "strings" 147 ["HELLO WORLD"]=> 148 string(7) "stringh" 149} 150 151-- Iteration 9 : undefined data -- 152array(1) { 153 [""]=> 154 string(9) "undefined" 155} 156 157-- Iteration 10 : unset data -- 158array(1) { 159 [""]=> 160 string(5) "unset" 161} 162Done 163