1--TEST--
2Test array_unique() function : usage variations - associative array with different values
3--FILE--
4<?php
5/*
6 * Testing the functionality of array_unique() by passing different
7 * associative arrays having different values to $input argument.
8*/
9
10echo "*** Testing array_unique() : assoc. array with diff. values 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// associative arrays with different values
33$inputs = array (
34       // arrays with integer values
35/*1*/  array('0' => 0, '1' => 0),
36       array("one" => 1, 'two' => 2, "three" => 1, 4 => 1),
37
38       // arrays with float values
39/*3*/  array("float1" => 2.3333, "float2" => 2.3333),
40       array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 1.2),
41
42       // arrays with string values
43/*5*/  array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 =>  "\tHello"),
44       array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 =>  '\tHello'),
45       array(1 => "hello", "heredoc" => $heredoc, $heredoc),
46
47       // array with object, unset variable and resource variable
48/*8*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp, new classA(), $fp),
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. values to $input argument ***
65-- Iteration 1 --
66array(1) {
67  [0]=>
68  int(0)
69}
70-- Iteration 2 --
71array(2) {
72  ["one"]=>
73  int(1)
74  ["two"]=>
75  int(2)
76}
77-- Iteration 3 --
78array(1) {
79  ["float1"]=>
80  float(2.3333)
81}
82-- Iteration 4 --
83array(3) {
84  ["f1"]=>
85  float(1.2)
86  ["f2"]=>
87  float(3.33)
88  [3]=>
89  float(4.89999922839999)
90}
91-- Iteration 5 --
92array(3) {
93  [111]=>
94  string(6) "	Hello"
95  ["red"]=>
96  string(6) "col	or"
97  [2]=>
98  string(7) "world"
99}
100-- Iteration 6 --
101array(3) {
102  [111]=>
103  string(7) "\tHello"
104  ["red"]=>
105  string(7) "col\tor"
106  [2]=>
107  string(9) "\v\fworld"
108}
109-- Iteration 7 --
110array(2) {
111  [1]=>
112  string(5) "hello"
113  ["heredoc"]=>
114  string(11) "Hello world"
115}
116-- Iteration 8 --
117array(3) {
118  [11]=>
119  object(classA)#%d (0) {
120  }
121  ["unset"]=>
122  NULL
123  ["resource"]=>
124  resource(%d) of type (stream)
125}
126Done
127