1--TEST-- 2Test natcasesort() function : usage variations - Pass arrays of different data types 3--FILE-- 4<?php 5 6/* 7 * Pass arrays of different data types to natcasesort() to test how they are sorted 8 */ 9 10echo "*** Testing natcasesort() : usage variation ***\n"; 11 12//get an unset variable 13$unset_var = 10; 14unset ($unset_var); 15 16// get a class 17class classA 18{ 19 public function __toString() { 20 return "Class A object"; 21 } 22} 23 24// heredoc string 25$heredoc = <<<EOT 26hello world 27EOT; 28 29// get a resource variable 30$fp = fopen(__FILE__, "r"); 31 32// arrays of different data types to be passed to $array_arg argument 33$inputs = array( 34 35 // int data 36/*1*/ 'int' => array( 37 0, 38 1, 39 12345, 40 -2345, 41 ), 42 43 // float data 44/*2*/ 'float' => array( 45 10.5, 46 -10.5, 47 12.3456789000e10, 48 12.3456789000E-10, 49 .5, 50 ), 51 52 // null data 53/*3*/ 'null' => array( 54 NULL, 55 null, 56 ), 57 58 // boolean data 59/*4*/ 'bool' => array( 60 true, 61 false, 62 TRUE, 63 FALSE, 64 ), 65 66 // empty data 67/*5*/ 'empty string' => array( 68 "", 69 '', 70 ), 71 72/*6*/ 'empty array' => array( 73 ), 74 75 // string data 76/*7*/ 'string' => array( 77 "string", 78 'string', 79 $heredoc, 80 ), 81 82 // object data 83/*8*/ 'object' => array( 84 new classA(), 85 ), 86 87 // undefined data 88/*9*/ 'undefined' => array( 89 @$undefined_var, 90 ), 91 92 // unset data 93/*10*/ 'unset' => array( 94 @$unset_var, 95 ), 96 97 // resource variable 98/*11*/ 'resource' => array( 99 $fp 100 ), 101); 102// loop through each element of $inputs to check the behavior of natcasesort() 103$iterator = 1; 104foreach($inputs as $input) { 105 echo "\n-- Iteration $iterator --\n"; 106 var_dump( natcasesort($input) ); 107 var_dump($input); 108 $iterator++; 109}; 110 111fclose($fp); 112 113echo "Done"; 114?> 115--EXPECTF-- 116*** Testing natcasesort() : usage variation *** 117 118-- Iteration 1 -- 119bool(true) 120array(4) { 121 [3]=> 122 int(-2345) 123 [0]=> 124 int(0) 125 [1]=> 126 int(1) 127 [2]=> 128 int(12345) 129} 130 131-- Iteration 2 -- 132bool(true) 133array(5) { 134 [1]=> 135 float(-10.5) 136 [4]=> 137 float(0.5) 138 [3]=> 139 float(1.23456789E-9) 140 [0]=> 141 float(10.5) 142 [2]=> 143 float(123456789000) 144} 145 146-- Iteration 3 -- 147bool(true) 148array(2) { 149 [0]=> 150 NULL 151 [1]=> 152 NULL 153} 154 155-- Iteration 4 -- 156bool(true) 157array(4) { 158 [1]=> 159 bool(false) 160 [3]=> 161 bool(false) 162 [0]=> 163 bool(true) 164 [2]=> 165 bool(true) 166} 167 168-- Iteration 5 -- 169bool(true) 170array(2) { 171 [0]=> 172 string(0) "" 173 [1]=> 174 string(0) "" 175} 176 177-- Iteration 6 -- 178bool(true) 179array(0) { 180} 181 182-- Iteration 7 -- 183bool(true) 184array(3) { 185 [2]=> 186 string(11) "hello world" 187 [0]=> 188 string(6) "string" 189 [1]=> 190 string(6) "string" 191} 192 193-- Iteration 8 -- 194bool(true) 195array(1) { 196 [0]=> 197 object(classA)#%d (0) { 198 } 199} 200 201-- Iteration 9 -- 202bool(true) 203array(1) { 204 [0]=> 205 NULL 206} 207 208-- Iteration 10 -- 209bool(true) 210array(1) { 211 [0]=> 212 NULL 213} 214 215-- Iteration 11 -- 216bool(true) 217array(1) { 218 [0]=> 219 resource(%d) of type (stream) 220} 221Done 222