1--TEST-- 2Test array_unique() function : usage variations - associative array with different values 3--FILE-- 4<?php 5/* Prototype : array array_unique(array $input) 6 * Description: Removes duplicate values from array 7 * Source code: ext/standard/array.c 8*/ 9 10/* 11 * Testing the functionality of array_unique() by passing different 12 * associative arrays having different values to $input argument. 13*/ 14 15echo "*** Testing array_unique() : assoc. array with diff. values to \$input argument ***\n"; 16 17// get an unset variable 18$unset_var = 10; 19unset ($unset_var); 20 21// get a resource variable 22$fp = fopen(__FILE__, "r"); 23 24// get a class 25class classA 26{ 27 public function __toString() { 28 return "Class A object"; 29 } 30} 31 32// get a heredoc string 33$heredoc = <<<EOT 34Hello world 35EOT; 36 37// associative arrays with different values 38$inputs = array ( 39 // arrays with integer values 40/*1*/ array('0' => 0, '1' => 0), 41 array("one" => 1, 'two' => 2, "three" => 1, 4 => 1), 42 43 // arrays with float values 44/*3*/ array("float1" => 2.3333, "float2" => 2.3333), 45 array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 1.2), 46 47 // arrays with string values 48/*5*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "\tHello"), 49 array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => '\tHello'), 50 array(1 => "hello", "heredoc" => $heredoc, $heredoc), 51 52 // array with object, unset variable and resource variable 53/*8*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp, new classA(), $fp), 54); 55 56// loop through each sub-array of $inputs to check the behavior of array_unique() 57$iterator = 1; 58foreach($inputs as $input) { 59 echo "-- Iteration $iterator --\n"; 60 var_dump( array_unique($input) ); 61 $iterator++; 62} 63 64fclose($fp); 65 66echo "Done"; 67?> 68--EXPECTF-- 69*** Testing array_unique() : assoc. array with diff. values to $input argument *** 70-- Iteration 1 -- 71array(1) { 72 [0]=> 73 int(0) 74} 75-- Iteration 2 -- 76array(2) { 77 ["one"]=> 78 int(1) 79 ["two"]=> 80 int(2) 81} 82-- Iteration 3 -- 83array(1) { 84 ["float1"]=> 85 float(2.3333) 86} 87-- Iteration 4 -- 88array(3) { 89 ["f1"]=> 90 float(1.2) 91 ["f2"]=> 92 float(3.33) 93 [3]=> 94 float(4.8999992284) 95} 96-- Iteration 5 -- 97array(3) { 98 [111]=> 99 string(6) " Hello" 100 ["red"]=> 101 string(6) "col or" 102 [2]=> 103 string(7) "world" 104} 105-- Iteration 6 -- 106array(3) { 107 [111]=> 108 string(7) "\tHello" 109 ["red"]=> 110 string(7) "col\tor" 111 [2]=> 112 string(9) "\v\fworld" 113} 114-- Iteration 7 -- 115array(2) { 116 [1]=> 117 string(5) "hello" 118 ["heredoc"]=> 119 string(11) "Hello world" 120} 121-- Iteration 8 -- 122array(3) { 123 [11]=> 124 object(classA)#%d (0) { 125 } 126 ["unset"]=> 127 NULL 128 ["resource"]=> 129 resource(%d) of type (stream) 130} 131Done 132