1--TEST--
2Test array_unique() function : usage variations - associative array with different keys
3--FILE--
4<?php
5/*
6 * Testing the functionality of array_unique() by passing different
7 * associative arrays having different keys to $input argument.
8*/
9
10echo "*** Testing array_unique() : assoc. array with diff. keys passed to \$input argument ***\n";
11
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 associative arrays to be passed to $input argument
33$inputs = array (
34/*1*/  // arrays with integer keys
35       array(0 => "0", 1 => "0"),
36       array(1 => "1", 2 => "2", 3 => 1, 4 => "4"),
37
38       // arrays with float keys
39/*3*/  array(2.3333 => "float", 44.44 => "float"),
40       array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f1", 3333333.333333 => "f4"),
41
42       // arrays with string keys
43/*5*/  array('\tHello' => 111, 're\td' => "color", '\v\fworld' => 2.2, 'pen\n' => 111),
44       array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 111),
45       array("hello", $heredoc => "string", "string"),
46
47       // array with object, unset variable and resource variable
48/*8*/ array(@$unset_var => "hello", $fp => 'resource', 11, "hello"),
49);
50
51// loop through each sub-array of $inputs to check the behavior of array_unique()
52$iterator = 1;
53foreach($inputs as $input) {
54  echo "-- Iteration $iterator --\n";
55  var_dump( array_unique($input) );
56  $iterator++;
57}
58
59fclose($fp);
60
61echo "Done";
62?>
63--EXPECTF--
64*** Testing array_unique() : assoc. array with diff. keys passed to $input argument ***
65
66Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
67-- Iteration 1 --
68array(1) {
69  [0]=>
70  string(1) "0"
71}
72-- Iteration 2 --
73array(3) {
74  [1]=>
75  string(1) "1"
76  [2]=>
77  string(1) "2"
78  [4]=>
79  string(1) "4"
80}
81-- Iteration 3 --
82array(1) {
83  [2]=>
84  string(5) "float"
85}
86-- Iteration 4 --
87array(3) {
88  [1]=>
89  string(2) "f1"
90  [3]=>
91  string(2) "f2"
92  [3333333]=>
93  string(2) "f4"
94}
95-- Iteration 5 --
96array(3) {
97  ["\tHello"]=>
98  int(111)
99  ["re\td"]=>
100  string(5) "color"
101  ["\v\fworld"]=>
102  float(2.2)
103}
104-- Iteration 6 --
105array(3) {
106  ["	Hello"]=>
107  int(111)
108  ["re	d"]=>
109  string(5) "color"
110  ["world"]=>
111  float(2.2)
112}
113-- Iteration 7 --
114array(2) {
115  [0]=>
116  string(5) "hello"
117  ["Hello world"]=>
118  string(6) "string"
119}
120-- Iteration 8 --
121array(3) {
122  [""]=>
123  string(5) "hello"
124  [5]=>
125  string(8) "resource"
126  [6]=>
127  int(11)
128}
129Done
130