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