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 string values
39/*5*/  array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3 =>  "\tHello"),
40       array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3 =>  '\tHello'),
41       array(1 => "hello", "heredoc" => $heredoc, $heredoc),
42
43       // array with object, unset variable and resource variable
44/*8*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp, new classA(), $fp),
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. values to $input argument ***
61-- Iteration 1 --
62array(1) {
63  [0]=>
64  int(0)
65}
66-- Iteration 2 --
67array(2) {
68  ["one"]=>
69  int(1)
70  ["two"]=>
71  int(2)
72}
73-- Iteration 3 --
74array(3) {
75  [111]=>
76  string(6) "	Hello"
77  ["red"]=>
78  string(6) "col	or"
79  [2]=>
80  string(7) "world"
81}
82-- Iteration 4 --
83array(3) {
84  [111]=>
85  string(7) "\tHello"
86  ["red"]=>
87  string(7) "col\tor"
88  [2]=>
89  string(9) "\v\fworld"
90}
91-- Iteration 5 --
92array(2) {
93  [1]=>
94  string(5) "hello"
95  ["heredoc"]=>
96  string(11) "Hello world"
97}
98-- Iteration 6 --
99array(3) {
100  [11]=>
101  object(classA)#%d (0) {
102  }
103  ["unset"]=>
104  NULL
105  ["resource"]=>
106  resource(%d) of type (stream)
107}
108Done
109