1--TEST-- 2Test array_diff_assoc() function : usage variations - arrays with different data types as keys 3--FILE-- 4<?php 5/* 6 * Test how array_diff_assoc() compares arrays containing different data types 7 * as keys 8 */ 9 10echo "\n*** Testing array_diff_assoc() : usage variations ***\n"; 11 12$array = array(1, 2, 3); 13 14//get an unset variable 15$unset_var = 10; 16unset ($unset_var); 17 18// heredoc string 19$heredoc = <<<EOT 20hello world 21EOT; 22 23//Different data types as keys to be passed to $arr1 argument 24$inputs = array( 25 26 // int data 27/*1*/ 28'int' => array( 29 0 => 'zero', 30 1 => 'one', 31 12345 => 'positive', 32 -2345 => 'negative'), 33 34 // float data 35/*2*/ 36'float' => array( 37 10.5 => 'float 1', 38 -10.5 => 'float 2', 39 .5 => 'float 3'), 40 41 // null data 42/*3*/ 43'null' => array( 44 NULL => 'null 1', 45 null => 'null 2'), 46 47 // boolean data 48/*4*/ 49'bool' => array( 50 true => 'boolt', 51 false => 'boolf', 52 TRUE => 'boolT', 53 FALSE => 'boolF'), 54 55 // empty data 56/*5*/ 57'empty' => array( 58 "" => 'emptyd', 59 '' => 'emptys'), 60 61 // string data 62/*6*/ 63'string' => array( 64 "string" => 'stringd', 65 'string' => 'strings', 66 $heredoc => 'stringh'), 67 68 // binary data 69/*7*/ 70'binary' => array( 71 b"binary1" => 'binary 1', 72 (binary)"binary2" => 'binary 2'), 73 74 // undefined data 75/*8*/ 76'undefined' => array( 77 @$undefined_var => 'undefined'), 78 79 // unset data 80/*9*/ 81'unset' => array( 82 @$unset_var => 'unset'), 83 84); 85 86// loop through each element of $inputs to check the behavior of array_diff_assoc 87$iterator = 1; 88foreach($inputs as $key => $input) { 89 echo "\n-- Iteration $iterator --\n"; 90 var_dump( array_diff_assoc($input, $array)); 91 $iterator++; 92}; 93 94echo "Done"; 95?> 96--EXPECT-- 97*** Testing array_diff_assoc() : usage variations *** 98 99-- Iteration 1 -- 100array(4) { 101 [0]=> 102 string(4) "zero" 103 [1]=> 104 string(3) "one" 105 [12345]=> 106 string(8) "positive" 107 [-2345]=> 108 string(8) "negative" 109} 110 111-- Iteration 2 -- 112array(3) { 113 [10]=> 114 string(7) "float 1" 115 [-10]=> 116 string(7) "float 2" 117 [0]=> 118 string(7) "float 3" 119} 120 121-- Iteration 3 -- 122array(1) { 123 [""]=> 124 string(6) "null 2" 125} 126 127-- Iteration 4 -- 128array(2) { 129 [1]=> 130 string(5) "boolT" 131 [0]=> 132 string(5) "boolF" 133} 134 135-- Iteration 5 -- 136array(1) { 137 [""]=> 138 string(6) "emptys" 139} 140 141-- Iteration 6 -- 142array(2) { 143 ["string"]=> 144 string(7) "strings" 145 ["hello world"]=> 146 string(7) "stringh" 147} 148 149-- Iteration 7 -- 150array(2) { 151 ["binary1"]=> 152 string(8) "binary 1" 153 ["binary2"]=> 154 string(8) "binary 2" 155} 156 157-- Iteration 8 -- 158array(1) { 159 [""]=> 160 string(9) "undefined" 161} 162 163-- Iteration 9 -- 164array(1) { 165 [""]=> 166 string(5) "unset" 167} 168Done 169