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