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 string keys
39/*5*/  array('\tHello' => 111, 're\td' => "color", '\v\fworld' => 2.2, 'pen\n' => 111),
40       array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 111),
41       array("hello", $heredoc => "string", "string"),
42
43       // array with object, unset variable and resource variable
44/*8*/ array(@$unset_var => "hello", $fp => 'resource', 11, "hello"),
45);
46
47// loop through each sub-array of $inputs to check the behavior of array_unique()
48$iterator = 1;
49foreach($inputs as $input) {
50  echo "-- Iteration $iterator --\n";
51  var_dump( array_unique($input) );
52  $iterator++;
53}
54
55fclose($fp);
56
57echo "Done";
58?>
59--EXPECTF--
60*** Testing array_unique() : assoc. array with diff. keys passed to $input argument ***
61
62Warning: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d
63-- Iteration 1 --
64array(1) {
65  [0]=>
66  string(1) "0"
67}
68-- Iteration 2 --
69array(3) {
70  [1]=>
71  string(1) "1"
72  [2]=>
73  string(1) "2"
74  [4]=>
75  string(1) "4"
76}
77-- Iteration 3 --
78array(3) {
79  ["\tHello"]=>
80  int(111)
81  ["re\td"]=>
82  string(5) "color"
83  ["\v\fworld"]=>
84  float(2.2)
85}
86-- Iteration 4 --
87array(3) {
88  ["	Hello"]=>
89  int(111)
90  ["re	d"]=>
91  string(5) "color"
92  ["world"]=>
93  float(2.2)
94}
95-- Iteration 5 --
96array(2) {
97  [0]=>
98  string(5) "hello"
99  ["Hello world"]=>
100  string(6) "string"
101}
102-- Iteration 6 --
103array(3) {
104  [""]=>
105  string(5) "hello"
106  [5]=>
107  string(8) "resource"
108  [6]=>
109  int(11)
110}
111Done
112