1--TEST-- 2Test array_shift() function : usage variations - Pass array with different data types as keys 3--FILE-- 4<?php 5/* Prototype : mixed array_shift(array &$stack) 6 * Description: Pops an element off the beginning of the array 7 * Source code: ext/standard/array.c 8 */ 9 10/* 11 * Pass arrays with different data types as keys to test how array_shift() re-assigns keys 12 */ 13 14echo "*** Testing array_shift() : 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// unexpected values to be passed to $stack argument 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.3456789000e10 => '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 95// loop through each element of $inputs to check the behavior of array_shift() 96$iterator = 1; 97foreach($inputs as $key => $input) { 98 echo "\n-- Iteration $iterator : $key data --\n"; 99 var_dump( array_shift($input) ); 100 var_dump($input); 101 $iterator++; 102}; 103 104echo "Done"; 105?> 106--EXPECT-- 107*** Testing array_shift() : usage variations *** 108 109-- Iteration 1 : int data -- 110string(4) "zero" 111array(3) { 112 [0]=> 113 string(3) "one" 114 [1]=> 115 string(8) "positive" 116 [2]=> 117 string(8) "negative" 118} 119 120-- Iteration 2 : float data -- 121string(8) "positive" 122array(2) { 123 [0]=> 124 string(8) "negative" 125 [1]=> 126 string(4) "half" 127} 128 129-- Iteration 3 : extreme floats data -- 130string(5) "large" 131array(1) { 132 [0]=> 133 string(5) "small" 134} 135 136-- Iteration 4 : null uppercase data -- 137string(6) "null 1" 138array(0) { 139} 140 141-- Iteration 5 : null lowercase data -- 142string(6) "null 2" 143array(0) { 144} 145 146-- Iteration 6 : bool lowercase data -- 147string(6) "lowert" 148array(1) { 149 [0]=> 150 string(6) "lowerf" 151} 152 153-- Iteration 7 : bool uppercase data -- 154string(6) "uppert" 155array(1) { 156 [0]=> 157 string(6) "upperf" 158} 159 160-- Iteration 8 : empty double quotes data -- 161string(6) "emptyd" 162array(0) { 163} 164 165-- Iteration 9 : empty single quotes data -- 166string(6) "emptys" 167array(0) { 168} 169 170-- Iteration 10 : string data -- 171string(7) "stringd" 172array(2) { 173 ["strings"]=> 174 string(7) "strings" 175 ["hello world"]=> 176 string(7) "stringh" 177} 178 179-- Iteration 11 : undefined data -- 180string(9) "undefined" 181array(0) { 182} 183 184-- Iteration 12 : unset data -- 185string(5) "unset" 186array(0) { 187} 188Done 189