2 Test array_shift() function
5 /* Prototype: mixed array_shift( array &array );
6 * Description: Shifts the first value of the array off and returns it.
11 $empty_array = array();
16 /* Various combinations of arrays to be used for the test */
19 array( 1,2,3,4,5,6,7,8,9 ),
20 array( "One", "_Two", "Three", "Four", "Five" ),
21 array( 6, "six", 7, "seven", 8, "eight", 9, "nine" ),
22 array( "a" => "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ),
23 array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ),
24 array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ),
25 array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2.4 => "float", "F" => "FFF",
26 "blank" => "", 3.7 => 3.7, 5.4 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ),
27 array( 12, "name", 'age', '45' ),
28 array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ),
29 array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6,
30 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 )
33 /* Testing Error Conditions */
34 echo "\n*** Testing Error Conditions ***\n";
36 /* Empty Array as argument */
37 var_dump( array_shift($empty_array) );
39 /* Loop to test normal functionality with different arrays inputs */
40 echo "\n*** Testing with various array inputs ***\n";
43 foreach( $mixed_array as $sub_array ) {
44 echo "\n-- Input Array for Iteration $counter is -- \n";
45 print_r( $sub_array );
46 echo "\nOutput after shift is :\n";
47 var_dump( array_shift($sub_array) );
51 /*Checking for internal array pointer beint reset when shift is called */
53 echo"\n*** Checking for internal array pointer being reset when shift is called ***\n";
55 echo "\nCurrent Element is : ";
56 var_dump( current($mixed_array[1]) );
58 echo "\nNext Element is : ";
59 var_dump( next($mixed_array[1]) );
61 echo "\nNext Element is : ";
62 var_dump( next($mixed_array[1]) );
64 echo "\nshifted Element is : ";
65 var_dump( array_shift($mixed_array[1]) );
67 echo "\nCurrent Element after shift operation is: ";
68 var_dump( current($mixed_array[1]) );
73 *** Testing Error Conditions ***
76 *** Testing with various array inputs ***
78 -- Input Array for Iteration 1 is --
83 Output after shift is :
86 -- Input Array for Iteration 2 is --
100 Output after shift is :
103 -- Input Array for Iteration 3 is --
113 Output after shift is :
116 -- Input Array for Iteration 4 is --
129 Output after shift is :
132 -- Input Array for Iteration 5 is --
142 Output after shift is :
145 -- Input Array for Iteration 6 is --
155 Output after shift is :
158 -- Input Array for Iteration 7 is --
168 Output after shift is :
171 -- Input Array for Iteration 8 is --
188 Output after shift is :
191 -- Input Array for Iteration 9 is --
200 Output after shift is :
203 -- Input Array for Iteration 10 is --
228 Output after shift is :
238 -- Input Array for Iteration 11 is --
253 Output after shift is :
256 *** Checking for internal array pointer being reset when shift is called ***
258 Current Element is : int(1)
260 Next Element is : int(2)
262 Next Element is : int(3)
264 shifted Element is : int(1)
266 Current Element after shift operation is: int(2)