1--TEST-- 2Test array_push() function : usage variations - array keys are different data types 3--FILE-- 4<?php 5/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) 6 * Description: Pushes elements onto the end of the array 7 * Source code: ext/standard/array.c 8 */ 9 10/* 11 * Pass array_push arrays where the keys are different data types. 12 */ 13 14echo "*** Testing array_push() : usage variations ***\n"; 15 16// Initialise function arguments not being substituted 17$var = 'value'; 18 19//get an unset variable 20$unset_var = 10; 21unset ($unset_var); 22 23// heredoc string 24$heredoc = <<<EOT 25hello world 26EOT; 27 28// arrays of different data types as keys to be passed to $stack argument 29$inputs = array( 30 31 // int data 32/*1*/ 'int' => array( 33 0 => 'zero', 34 1 => 'one', 35 12345 => 'positive', 36 -2345 => 'negative', 37 ), 38 39 // float data 40/*2*/ 'float' => array( 41 10.5 => 'positive', 42 -10.5 => 'negative', 43 .5 => 'half', 44 ), 45 46 'extreme floats' => array( 47 12.3456789000e10 => 'large', 48 12.3456789000E-10 => 'small', 49 ), 50 51 // null data 52/*3*/ 'null uppercase' => array( 53 NULL => 'null 1', 54 ), 55 'null lowercase' => array( 56 null => 'null 2', 57 ), 58 59 // boolean data 60/*4*/ 'bool lowercase' => array( 61 true => 'lowert', 62 false => 'lowerf', 63 ), 64 'bool uppercase' => array( 65 TRUE => 'uppert', 66 FALSE => 'upperf', 67 ), 68 69 // empty data 70/*5*/ 'empty double quotes' => array( 71 "" => 'emptyd', 72 ), 73 'empty single quotes' => array( 74 '' => 'emptys', 75 ), 76 77 // string data 78/*6*/ 'string' => array( 79 "stringd" => 'stringd', 80 'strings' => 'strings', 81 $heredoc => 'stringh', 82 ), 83 84 // undefined data 85/*8*/ 'undefined' => array( 86 @$undefined_var => 'undefined', 87 ), 88 89 // unset data 90/*9*/ 'unset' => array( 91 @$unset_var => 'unset', 92 ), 93); 94 95// loop through each sub-array of $inputs to check the behavior of array_push() 96$iterator = 1; 97foreach($inputs as $key => $input) { 98 echo "\n-- Iteration $iterator : $key data --\n"; 99 echo "Before : "; 100 var_dump(count($input)); 101 echo "After : "; 102 var_dump( array_push($input, $var) ); 103 $iterator++; 104}; 105 106echo "Done"; 107?> 108 109--EXPECTF-- 110*** Testing array_push() : usage variations *** 111 112-- Iteration 1 : int data -- 113Before : int(4) 114After : int(5) 115 116-- Iteration 2 : float data -- 117Before : int(3) 118After : int(4) 119 120-- Iteration 3 : extreme floats data -- 121Before : int(2) 122After : int(3) 123 124-- Iteration 4 : null uppercase data -- 125Before : int(1) 126After : int(2) 127 128-- Iteration 5 : null lowercase data -- 129Before : int(1) 130After : int(2) 131 132-- Iteration 6 : bool lowercase data -- 133Before : int(2) 134After : int(3) 135 136-- Iteration 7 : bool uppercase data -- 137Before : int(2) 138After : int(3) 139 140-- Iteration 8 : empty double quotes data -- 141Before : int(1) 142After : int(2) 143 144-- Iteration 9 : empty single quotes data -- 145Before : int(1) 146After : int(2) 147 148-- Iteration 10 : string data -- 149Before : int(3) 150After : int(4) 151 152-- Iteration 11 : undefined data -- 153Before : int(1) 154After : int(2) 155 156-- Iteration 12 : unset data -- 157Before : int(1) 158After : int(2) 159Done 160