2 Test key(), current(), next() & reset() functions
6 mixed key ( array &$array ) -> returns the index element of the current array position
7 mixed current ( array &$array ) -> returns the current element in the array
8 mixed next ( array &$array ) -> similar to current() but advances the internal pointer to next element
9 mixed reset ( array &$array ) -> Reset the internal pointer to first element
12 $basic_arrays = array (
13 array(0), // array with element as 0
14 array(1), // array with single element
15 array(1,2, 3, -1, -2, -3), // array of integers
16 array(1.1, 2.2, 3.3, -1.1, -2.2, -3.3), // array of floats
17 array('a', 'b', 'c', "ab", "ac", "ad"), // string array
18 array("a" => "apple", "b" => "book", "c" => "cook"), // associative array
19 array('d' => 'drink', 'p' => 'port', 's' => 'set'), // another associative array
20 array(1 => 'One', 2 => 'two', 3 => "three") // associative array with key as integers
23 $varient_arrays = array (
24 array(), // empty array
25 array(""), // array with null string
26 array(NULL),// array with NULL
27 array(null),// array with null
28 array(NULL, true, null, "", 1), // mixed array
29 array(-1.5 => "test", -2 => "rest", 2.5 => "two",
30 "" => "string", 0 => "zero", "" => "" ) // mixed array
33 echo "*** Testing basic operations ***\n";
35 foreach ($basic_arrays as $sub_array ) {
36 echo "-- Iteration $loop_count --\n";
38 $c = count ($sub_array);
39 $c++; // increment by one to create the situation of accessing beyond array size
41 var_dump( current($sub_array)); // current element
42 var_dump( key($sub_array) ); // key of the current element
43 var_dump( next($sub_array) ); // move to next element
46 var_dump( reset($sub_array) ); // reset the internal pointer to first element
47 var_dump( key($sub_array) ); // access the array after reset
48 var_dump( $sub_array ); // dump the array to see that its intact
53 echo "\n*** Testing possible variations ***\n";
55 foreach ($varient_arrays as $sub_array ) {
56 echo "-- Iteration $loop_count --\n";
58 $c = count ($sub_array);
59 $c++; // increment by one to create the situation of accessing beyond array size
61 var_dump( current($sub_array)); // current element
62 var_dump( key($sub_array) ); // key of the current element
63 var_dump( next($sub_array) ); // move to next element
66 var_dump( reset($sub_array) ); // reset the internal pointer to first element
67 var_dump( key($sub_array) ); // access the array after reset
68 var_dump( $sub_array ); // dump the array to see that its intact
75 *** Testing basic operations ***
294 *** Testing possible variations ***