1--TEST-- 2Test array_key_exists() function : usage variations - array keys are different data types 3--FILE-- 4<?php 5/* 6 * Pass an array where the keys are different data types as the $search argument 7 * then pass many different data types as $key argument to test where array_key_exist() 8 * returns true. 9 */ 10 11echo "*** Testing array_key_exists() : usage variations ***\n"; 12 13//get an unset variable 14$unset_var = 10; 15unset ($unset_var); 16 17// heredoc string 18$heredoc = <<<EOT 19string 20EOT; 21 22// different data types to be iterated over 23$inputs = array( 24 25 // int data 26/*1*/ 'int' => array( 27 0 => 'zero', 28 1 => 'one', 29 12345 => 'positive', 30 -2345 => 'negative', 31 ), 32 33 // null data 34/*3*/ 'null uppercase' => array( 35 NULL => 'null 1', 36 ), 37 'null lowercase' => array( 38 null => 'null 2', 39 ), 40 41 // boolean data 42/*4*/ 'bool lowercase' => array( 43 true => 'lowert', 44 false => 'lowerf', 45 ), 46 'bool uppercase' => array( 47 TRUE => 'uppert', 48 FALSE => 'upperf', 49 ), 50 51 // empty data 52/*5*/ 'empty double quotes' => array( 53 "" => 'emptyd', 54 ), 55 'empty single quotes' => array( 56 '' => 'emptys', 57 ), 58 59 // string data 60/*6*/ 'string' => array( 61 "stringd" => 'stringd', 62 'strings' => 'strings', 63 $heredoc => 'stringh', 64 ), 65 66 // undefined data 67/*8*/ 'undefined' => array( 68 @$undefined_var => 'undefined', 69 ), 70 71 // unset data 72/*9*/ 'unset' => array( 73 @$unset_var => 'unset', 74 ), 75); 76 77// loop through each element of $inputs to check the behavior of array_key_exists() 78$iterator = 1; 79foreach($inputs as $type => $input) { 80 echo "\n-- Iteration $iterator: $type data --\n"; 81 82 //iterate over again to get all different key values 83 foreach ($inputs as $new_type => $new_input) { 84 echo "-- \$key arguments are $new_type data:\n"; 85 foreach ($new_input as $key => $search) { 86 var_dump(array_key_exists($key, $input)); 87 } 88 } 89 $iterator++; 90}; 91 92echo "Done"; 93?> 94--EXPECT-- 95*** Testing array_key_exists() : usage variations *** 96 97-- Iteration 1: int data -- 98-- $key arguments are int data: 99bool(true) 100bool(true) 101bool(true) 102bool(true) 103-- $key arguments are null uppercase data: 104bool(false) 105-- $key arguments are null lowercase data: 106bool(false) 107-- $key arguments are bool lowercase data: 108bool(true) 109bool(true) 110-- $key arguments are bool uppercase data: 111bool(true) 112bool(true) 113-- $key arguments are empty double quotes data: 114bool(false) 115-- $key arguments are empty single quotes data: 116bool(false) 117-- $key arguments are string data: 118bool(false) 119bool(false) 120bool(false) 121-- $key arguments are undefined data: 122bool(false) 123-- $key arguments are unset data: 124bool(false) 125 126-- Iteration 2: null uppercase data -- 127-- $key arguments are int data: 128bool(false) 129bool(false) 130bool(false) 131bool(false) 132-- $key arguments are null uppercase data: 133bool(true) 134-- $key arguments are null lowercase data: 135bool(true) 136-- $key arguments are bool lowercase data: 137bool(false) 138bool(false) 139-- $key arguments are bool uppercase data: 140bool(false) 141bool(false) 142-- $key arguments are empty double quotes data: 143bool(true) 144-- $key arguments are empty single quotes data: 145bool(true) 146-- $key arguments are string data: 147bool(false) 148bool(false) 149bool(false) 150-- $key arguments are undefined data: 151bool(true) 152-- $key arguments are unset data: 153bool(true) 154 155-- Iteration 3: null lowercase data -- 156-- $key arguments are int data: 157bool(false) 158bool(false) 159bool(false) 160bool(false) 161-- $key arguments are null uppercase data: 162bool(true) 163-- $key arguments are null lowercase data: 164bool(true) 165-- $key arguments are bool lowercase data: 166bool(false) 167bool(false) 168-- $key arguments are bool uppercase data: 169bool(false) 170bool(false) 171-- $key arguments are empty double quotes data: 172bool(true) 173-- $key arguments are empty single quotes data: 174bool(true) 175-- $key arguments are string data: 176bool(false) 177bool(false) 178bool(false) 179-- $key arguments are undefined data: 180bool(true) 181-- $key arguments are unset data: 182bool(true) 183 184-- Iteration 4: bool lowercase data -- 185-- $key arguments are int data: 186bool(true) 187bool(true) 188bool(false) 189bool(false) 190-- $key arguments are null uppercase data: 191bool(false) 192-- $key arguments are null lowercase data: 193bool(false) 194-- $key arguments are bool lowercase data: 195bool(true) 196bool(true) 197-- $key arguments are bool uppercase data: 198bool(true) 199bool(true) 200-- $key arguments are empty double quotes data: 201bool(false) 202-- $key arguments are empty single quotes data: 203bool(false) 204-- $key arguments are string data: 205bool(false) 206bool(false) 207bool(false) 208-- $key arguments are undefined data: 209bool(false) 210-- $key arguments are unset data: 211bool(false) 212 213-- Iteration 5: bool uppercase data -- 214-- $key arguments are int data: 215bool(true) 216bool(true) 217bool(false) 218bool(false) 219-- $key arguments are null uppercase data: 220bool(false) 221-- $key arguments are null lowercase data: 222bool(false) 223-- $key arguments are bool lowercase data: 224bool(true) 225bool(true) 226-- $key arguments are bool uppercase data: 227bool(true) 228bool(true) 229-- $key arguments are empty double quotes data: 230bool(false) 231-- $key arguments are empty single quotes data: 232bool(false) 233-- $key arguments are string data: 234bool(false) 235bool(false) 236bool(false) 237-- $key arguments are undefined data: 238bool(false) 239-- $key arguments are unset data: 240bool(false) 241 242-- Iteration 6: empty double quotes data -- 243-- $key arguments are int data: 244bool(false) 245bool(false) 246bool(false) 247bool(false) 248-- $key arguments are null uppercase data: 249bool(true) 250-- $key arguments are null lowercase data: 251bool(true) 252-- $key arguments are bool lowercase data: 253bool(false) 254bool(false) 255-- $key arguments are bool uppercase data: 256bool(false) 257bool(false) 258-- $key arguments are empty double quotes data: 259bool(true) 260-- $key arguments are empty single quotes data: 261bool(true) 262-- $key arguments are string data: 263bool(false) 264bool(false) 265bool(false) 266-- $key arguments are undefined data: 267bool(true) 268-- $key arguments are unset data: 269bool(true) 270 271-- Iteration 7: empty single quotes data -- 272-- $key arguments are int data: 273bool(false) 274bool(false) 275bool(false) 276bool(false) 277-- $key arguments are null uppercase data: 278bool(true) 279-- $key arguments are null lowercase data: 280bool(true) 281-- $key arguments are bool lowercase data: 282bool(false) 283bool(false) 284-- $key arguments are bool uppercase data: 285bool(false) 286bool(false) 287-- $key arguments are empty double quotes data: 288bool(true) 289-- $key arguments are empty single quotes data: 290bool(true) 291-- $key arguments are string data: 292bool(false) 293bool(false) 294bool(false) 295-- $key arguments are undefined data: 296bool(true) 297-- $key arguments are unset data: 298bool(true) 299 300-- Iteration 8: string data -- 301-- $key arguments are int data: 302bool(false) 303bool(false) 304bool(false) 305bool(false) 306-- $key arguments are null uppercase data: 307bool(false) 308-- $key arguments are null lowercase data: 309bool(false) 310-- $key arguments are bool lowercase data: 311bool(false) 312bool(false) 313-- $key arguments are bool uppercase data: 314bool(false) 315bool(false) 316-- $key arguments are empty double quotes data: 317bool(false) 318-- $key arguments are empty single quotes data: 319bool(false) 320-- $key arguments are string data: 321bool(true) 322bool(true) 323bool(true) 324-- $key arguments are undefined data: 325bool(false) 326-- $key arguments are unset data: 327bool(false) 328 329-- Iteration 9: undefined data -- 330-- $key arguments are int data: 331bool(false) 332bool(false) 333bool(false) 334bool(false) 335-- $key arguments are null uppercase data: 336bool(true) 337-- $key arguments are null lowercase data: 338bool(true) 339-- $key arguments are bool lowercase data: 340bool(false) 341bool(false) 342-- $key arguments are bool uppercase data: 343bool(false) 344bool(false) 345-- $key arguments are empty double quotes data: 346bool(true) 347-- $key arguments are empty single quotes data: 348bool(true) 349-- $key arguments are string data: 350bool(false) 351bool(false) 352bool(false) 353-- $key arguments are undefined data: 354bool(true) 355-- $key arguments are unset data: 356bool(true) 357 358-- Iteration 10: unset data -- 359-- $key arguments are int data: 360bool(false) 361bool(false) 362bool(false) 363bool(false) 364-- $key arguments are null uppercase data: 365bool(true) 366-- $key arguments are null lowercase data: 367bool(true) 368-- $key arguments are bool lowercase data: 369bool(false) 370bool(false) 371-- $key arguments are bool uppercase data: 372bool(false) 373bool(false) 374-- $key arguments are empty double quotes data: 375bool(true) 376-- $key arguments are empty single quotes data: 377bool(true) 378-- $key arguments are string data: 379bool(false) 380bool(false) 381bool(false) 382-- $key arguments are undefined data: 383bool(true) 384-- $key arguments are unset data: 385bool(true) 386Done 387