import zend standard tests
[hiphop-php.git] / hphp / test / zend / bad / ext-standard-array / array_combine_variation4.php
blob1696ea34edbd6069a5a35d805a40d41720435c99
1 <?php
2 /* Prototype : array array_combine(array $keys, array $values)
3 * Description: Creates an array by using the elements of the first parameter as keys
4 * and the elements of the second as the corresponding values
5 * Source code: ext/standard/array.c
6 */
8 /*
9 * Testing the functionality of array_combine() by passing different
10 * associative arrays having different possible keys to $keys argument and
11 * associative arrays having different possible keys to $values argument.
14 echo "*** Testing array_combine() : assoc array with diff keys to both \$keys and \$values argument ***\n";
15 // get an unset variable
16 $unset_var = 10;
17 unset ($unset_var);
19 // get a resource variable
20 $fp = fopen(__FILE__, "r");
22 // get a class
23 class classA
25 public function __toString(){
26 return "Class A object";
30 // get a heredoc string
31 $heredoc = <<<EOT
32 Hello world
33 EOT;
35 // different variations of associative arrays to be passed to $arr1 argument
36 $arrays = array (
38 // empty array
39 /*1*/ array(),
41 // arrays with integer keys
42 array(0 => "0"),
43 array(1 => "1"),
44 array(1 => "1", 2 => "2", 3 => "3", 4 => "4"),
46 // arrays with float keys
47 /*5*/ array(2.3333 => "float"),
48 array(1.2 => "f1", 3.33 => "f2",
49 4.89999922839999 => "f3",
50 33333333.333333 => "f4"),
52 // arrays with string keys
53 /*7*/ array('\tHello' => 111, 're\td' => "color",
54 '\v\fworld' => 2.2, 'pen\n' => 33),
55 array("\tHello" => 111, "re\td" => "color",
56 "\v\fworld" => 2.2, "pen\n" => 33),
57 array("hello", $heredoc => "string"), // heredoc
59 // array with object, unset variable and resource variable
60 /*10*/ array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'),
62 // array with mixed keys
63 /*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2,
64 $fp => 'resource', 133 => "int", 444.432 => "float",
65 @$unset_var => "unset", $heredoc => "heredoc")
68 // array to be passsed to $arr2 argument
69 $arr2 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4",
70 "\tHello" => 111, 2.2, 'color', "Hello world" => "string",
71 "pen\n" => 33, new classA() => 11, 133 => "int");
73 // loop through each sub-array within $arrays to check the behavior of array_combine()
74 // same arrays are passed to both $keys and $values
75 $iterator = 1;
76 foreach($arrays as $array) {
77 echo "-- Iteration $iterator --\n";
78 var_dump( array_combine($array, $array) );
79 $iterator++;
82 // close the file resource used
83 fclose($fp);
85 echo "Done";