Revert "make hphpc able to use ini files"
[hiphop-php.git] / hphp / test / zend / bad / ext / standard / tests / array / 009.php
blobba4d1cfb0e45e76bbe19857b0295dca59b10c3b8
1 <?php
2 /* Prototype & Usage:
3 mixed key ( array &$array ) -> returns the index element of the current array position
4 mixed current ( array &$array ) -> returns the current element in the array
5 mixed next ( array &$array ) -> similar to current() but advances the internal pointer to next element
6 mixed reset ( array &$array ) -> Reset the internal pointer to first element
7 */
9 $basic_arrays = array (
10 array(0), // array with element as 0
11 array(1), // array with single element
12 array(1,2, 3, -1, -2, -3), // array of integers
13 array(1.1, 2.2, 3.3, -1.1, -2.2, -3.3), // array of floats
14 array('a', 'b', 'c', "ab", "ac", "ad"), // string array
15 array("a" => "apple", "b" => "book", "c" => "cook"), // associative array
16 array('d' => 'drink', 'p' => 'port', 's' => 'set'), // another associative array
17 array(1 => 'One', 2 => 'two', 3 => "three") // associative array with key as integers
20 $varient_arrays = array (
21 array(), // empty array
22 array(""), // array with null string
23 array(NULL),// array with NULL
24 array(null),// array with null
25 array(NULL, true, null, "", 1), // mixed array
26 array(-1.5 => "test", -2 => "rest", 2.5 => "two",
27 "" => "string", 0 => "zero", "" => "" ) // mixed array
28 );
30 echo "*** Testing basic operations ***\n";
31 $loop_count = 1;
32 foreach ($basic_arrays as $sub_array ) {
33 echo "-- Iteration $loop_count --\n";
34 $loop_count++;
35 $c = count ($sub_array);
36 $c++; // increment by one to create the situation of accessing beyond array size
37 while ( $c ) {
38 var_dump( current($sub_array)); // current element
39 var_dump( key($sub_array) ); // key of the current element
40 var_dump( next($sub_array) ); // move to next element
41 $c --;
43 var_dump( reset($sub_array) ); // reset the internal pointer to first element
44 var_dump( key($sub_array) ); // access the array after reset
45 var_dump( $sub_array ); // dump the array to see that its intact
47 echo "\n";
50 echo "\n*** Testing possible variations ***\n";
51 $loop_count = 1;
52 foreach ($varient_arrays as $sub_array ) {
53 echo "-- Iteration $loop_count --\n";
54 $loop_count++;
55 $c = count ($sub_array);
56 $c++; // increment by one to create the situation of accessing beyond array size
57 while ( $c ) {
58 var_dump( current($sub_array)); // current element
59 var_dump( key($sub_array) ); // key of the current element
60 var_dump( next($sub_array) ); // move to next element
61 $c --;
63 var_dump( reset($sub_array) ); // reset the internal pointer to first element
64 var_dump( key($sub_array) ); // access the array after reset
65 var_dump( $sub_array ); // dump the array to see that its intact
66 echo "\n";
69 /*test these functions on array which is already unset */
70 echo "\n-- Testing variation: when array is unset --\n";
71 $unset_array = array (1);
72 unset($unset_array);
74 var_dump( current($unset_array) );
75 var_dump( key($unset_array) );
76 var_dump( next($unset_array) );
77 var_dump( reset($unset_array) );
80 echo "\n*** Testing error conditions ***\n";
81 //Zero argument, expected 1 argument
82 var_dump( key() );
83 var_dump( current() );
84 var_dump( reset() );
85 var_dump( next() );
87 // args more than expected, expected 1 argument
88 $temp_array = array(1);
89 var_dump( key($temp_array, $temp_array) );
90 var_dump( current($temp_array, $temp_array) );
91 var_dump( reset($temp_array, $temp_array) );
92 var_dump( next($temp_array, $temp_array) );
94 // invalid args type, valid argument: array
95 $int_var = 1;
96 $float_var = 1.5;
97 $string = "string";
98 var_dump( key($int_var) );
99 var_dump( key($float_var) );
100 var_dump( key($string) );
102 var_dump( current($int_var) );
103 var_dump( current($float_var) );
104 var_dump( current($string) );
106 var_dump( next($int_var) );
107 var_dump( next($float_var) );
108 var_dump( next($string) );
110 var_dump( reset($int_var) );
111 var_dump( reset($float_var) );
112 var_dump( reset($string) );
114 echo "Done\n";