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