1--TEST--
2Test array_combine() function : usage variations - associative array with different keys(Bug#43424)
3--FILE--
4<?php
5/*
6 * Testing the functionality of array_combine() by passing different
7 * associative arrays having different possible keys to $keys argument and
8 * associative arrays having different possible keys to $values argument.
9*/
10
11echo "*** Testing array_combine() : assoc array with diff keys to both \$keys and \$values argument ***\n";
12// get an unset variable
13$unset_var = 10;
14unset ($unset_var);
15
16// get a resource variable
17$fp = fopen(__FILE__, "r");
18
19// get a class
20class classA
21{
22  public function __toString(){
23    return "Class A object";
24  }
25}
26
27// get a heredoc string
28$heredoc = <<<EOT
29Hello world
30EOT;
31
32// different variations of associative arrays to be passed to $arr1 argument
33$arrays = array (
34
35       // empty array
36/*1*/  array(),
37
38       // arrays with integer keys
39       array(0 => "0"),
40       array(1 => "1"),
41       array(1 => "1", 2 => "2", 3 => "3", 4 => "4"),
42
43       // arrays with string keys
44/*7*/  array('\tHello' => 111, 're\td' => "color",
45             '\v\fworld' => 2.2, 'pen\n' => 33),
46       array("\tHello" => 111, "re\td" => "color",
47             "\v\fworld" => 2.2, "pen\n" => 33),
48       array("hello", $heredoc => "string"), // heredoc
49
50       // array with object, unset variable and resource variable
51/*10*/ array(@$unset_var => "hello", $fp => 'resource'),
52
53       // array with mixed keys
54/*11*/ array('hello' => 1, "fruit" => 2.2,
55             $fp => 'resource', 133 => "int",
56             @$unset_var => "unset", $heredoc => "heredoc")
57);
58
59// array to be passsed to $arr2 argument
60$arr2 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4",
61              "\tHello" => 111, 2.2, 'color', "Hello world" => "string",
62              "pen\n" => 33, 133 => "int");
63
64// loop through each sub-array within $arrays to check the behavior of array_combine()
65// same arrays are passed to both $keys and $values
66$iterator = 1;
67foreach($arrays as $array) {
68  echo "-- Iteration $iterator --\n";
69  var_dump( array_combine($array, $array) );
70  $iterator++;
71}
72
73// close the file resource used
74fclose($fp);
75
76echo "Done";
77?>
78--EXPECTF--
79*** Testing array_combine() : assoc array with diff keys to both $keys and $values argument ***
80
81Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
82
83Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
84-- Iteration 1 --
85array(0) {
86}
87-- Iteration 2 --
88array(1) {
89  [0]=>
90  string(1) "0"
91}
92-- Iteration 3 --
93array(1) {
94  [1]=>
95  string(1) "1"
96}
97-- Iteration 4 --
98array(4) {
99  [1]=>
100  string(1) "1"
101  [2]=>
102  string(1) "2"
103  [3]=>
104  string(1) "3"
105  [4]=>
106  string(1) "4"
107}
108-- Iteration 5 --
109array(4) {
110  [111]=>
111  int(111)
112  ["color"]=>
113  string(5) "color"
114  ["2.2"]=>
115  float(2.2)
116  [33]=>
117  int(33)
118}
119-- Iteration 6 --
120array(4) {
121  [111]=>
122  int(111)
123  ["color"]=>
124  string(5) "color"
125  ["2.2"]=>
126  float(2.2)
127  [33]=>
128  int(33)
129}
130-- Iteration 7 --
131array(2) {
132  ["hello"]=>
133  string(5) "hello"
134  ["string"]=>
135  string(6) "string"
136}
137-- Iteration 8 --
138array(2) {
139  ["hello"]=>
140  string(5) "hello"
141  ["resource"]=>
142  string(8) "resource"
143}
144-- Iteration 9 --
145array(6) {
146  [1]=>
147  int(1)
148  ["2.2"]=>
149  float(2.2)
150  ["resource"]=>
151  string(8) "resource"
152  ["int"]=>
153  string(3) "int"
154  ["unset"]=>
155  string(5) "unset"
156  ["heredoc"]=>
157  string(7) "heredoc"
158}
159Done
160