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