1--TEST-- 2Test array_unshift() function : basic functionality - associative arrays for 'array' argument 3--FILE-- 4<?php 5/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) 6 * Description: Pushes elements onto the beginning of the array 7 * Source code: ext/standard/array.c 8*/ 9 10/* 11 * Testing array_unshift() by giving associative arrays for $array argument 12*/ 13 14echo "*** Testing array_unshift() : basic functionality with associative array ***\n"; 15 16// Initialise the array 17$array = array('f' => "first", "s" => 'second', 1 => "one", 2 => 'two'); 18 19// Calling array_unshift() with default argument 20$temp_array = $array; 21// returns element count in the resulting array after arguments are pushed to 22// beginning of the given array 23var_dump( array_unshift($temp_array, 10) ); 24 25// dump the resulting array 26var_dump($temp_array); 27 28// Calling array_unshift() with optional arguments 29$temp_array = $array; 30// returns element count in the resulting array after arguments are pushed to 31// beginning of the given array 32var_dump( array_unshift($temp_array, 222, "hello", 12.33) ); 33 34// dump the resulting array 35var_dump($temp_array); 36 37echo "Done"; 38?> 39--EXPECTF-- 40*** Testing array_unshift() : basic functionality with associative array *** 41int(5) 42array(5) { 43 [0]=> 44 int(10) 45 ["f"]=> 46 string(5) "first" 47 ["s"]=> 48 string(6) "second" 49 [1]=> 50 string(3) "one" 51 [2]=> 52 string(3) "two" 53} 54int(7) 55array(7) { 56 [0]=> 57 int(222) 58 [1]=> 59 string(5) "hello" 60 [2]=> 61 float(12.33) 62 ["f"]=> 63 string(5) "first" 64 ["s"]=> 65 string(6) "second" 66 [3]=> 67 string(3) "one" 68 [4]=> 69 string(3) "two" 70} 71Done