Return to array_unique_variation3.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / array |
1.1 misho 1: --TEST-- 2: Test array_unique() function : usage variations - associative array with different keys 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 keys to $input argument. 13: */ 14: 15: echo "*** Testing array_unique() : assoc. array with diff. keys passed to \$input argument ***\n"; 16: 17: // get an unset variable 18: $unset_var = 10; 19: unset ($unset_var); 20: 21: // get a resource variable 22: $fp = fopen(__FILE__, "r"); 23: 24: // get a class 25: class classA 26: { 27: public function __toString(){ 28: return "Class A object"; 29: } 30: } 31: 32: // get a heredoc string 33: $heredoc = <<<EOT 34: Hello world 35: EOT; 36: 37: // different associative arrays to be passed to $input argument 38: $inputs = array ( 39: /*1*/ // arrays with integer keys 40: array(0 => "0", 1 => "0"), 41: array(1 => "1", 2 => "2", 3 => 1, 4 => "4"), 42: 43: // arrays with float keys 44: /*3*/ array(2.3333 => "float", 44.44 => "float"), 45: array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f1", 3333333.333333 => "f4"), 46: 47: // arrays with string keys 48: /*5*/ array('\tHello' => 111, 're\td' => "color", '\v\fworld' => 2.2, 'pen\n' => 111), 49: array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 111), 50: array("hello", $heredoc => "string", "string"), 51: 52: // array with object, unset variable and resource variable 53: /*8*/ array(new classA() => 11, @$unset_var => "hello", $fp => 'resource', 11, "hello"), 54: ); 55: 56: // loop through each sub-array of $inputs to check the behavior of array_unique() 57: $iterator = 1; 58: foreach($inputs as $input) { 59: echo "-- Iteration $iterator --\n"; 60: var_dump( array_unique($input) ); 61: $iterator++; 62: } 63: 64: fclose($fp); 65: 66: echo "Done"; 67: ?> 68: --EXPECTF-- 69: *** Testing array_unique() : assoc. array with diff. keys passed to $input argument *** 70: 71: Warning: Illegal offset type in %s on line %d 72: 73: Warning: Illegal offset type in %s on line %d 74: -- Iteration 1 -- 75: array(1) { 76: [0]=> 77: string(1) "0" 78: } 79: -- Iteration 2 -- 80: array(3) { 81: [1]=> 82: string(1) "1" 83: [2]=> 84: string(1) "2" 85: [4]=> 86: string(1) "4" 87: } 88: -- Iteration 3 -- 89: array(1) { 90: [2]=> 91: string(5) "float" 92: } 93: -- Iteration 4 -- 94: array(3) { 95: [1]=> 96: string(2) "f1" 97: [3]=> 98: string(2) "f2" 99: [3333333]=> 100: string(2) "f4" 101: } 102: -- Iteration 5 -- 103: array(3) { 104: ["\tHello"]=> 105: int(111) 106: ["re\td"]=> 107: string(5) "color" 108: ["\v\fworld"]=> 109: float(2.2) 110: } 111: -- Iteration 6 -- 112: array(3) { 113: [" Hello"]=> 114: int(111) 115: ["re d"]=> 116: string(5) "color" 117: ["world"]=> 118: float(2.2) 119: } 120: -- Iteration 7 -- 121: array(2) { 122: [0]=> 123: string(5) "hello" 124: ["Hello world"]=> 125: string(6) "string" 126: } 127: -- Iteration 8 -- 128: array(2) { 129: [""]=> 130: string(5) "hello" 131: [0]=> 132: int(11) 133: } 134: Done