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--EXPECTF-- 109*** Testing array_push() : usage variations *** 110 111-- Iteration 1 : int data -- 112Before : int(4) 113After : int(5) 114 115-- Iteration 2 : float data -- 116Before : int(3) 117After : int(4) 118 119-- Iteration 3 : extreme floats data -- 120Before : int(2) 121After : int(3) 122 123-- Iteration 4 : null uppercase data -- 124Before : int(1) 125After : int(2) 126 127-- Iteration 5 : null lowercase data -- 128Before : int(1) 129After : int(2) 130 131-- Iteration 6 : bool lowercase data -- 132Before : int(2) 133After : int(3) 134 135-- Iteration 7 : bool uppercase data -- 136Before : int(2) 137After : int(3) 138 139-- Iteration 8 : empty double quotes data -- 140Before : int(1) 141After : int(2) 142 143-- Iteration 9 : empty single quotes data -- 144Before : int(1) 145After : int(2) 146 147-- Iteration 10 : string data -- 148Before : int(3) 149After : int(4) 150 151-- Iteration 11 : undefined data -- 152Before : int(1) 153After : int(2) 154 155-- Iteration 12 : unset data -- 156Before : int(1) 157After : int(2) 158Done 159