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