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 // float data 34/*2*/ 'float' => array( 35 10.5 => 'positive', 36 -10.5 => 'negative', 37 .5 => 'half', 38 ), 39 40 'extreme floats' => array( 41 12.3456789000e10 => 'large', 42 12.3456789000E-10 => 'small', 43 ), 44 45 // null data 46/*3*/ 'null uppercase' => array( 47 NULL => 'null 1', 48 ), 49 'null lowercase' => array( 50 null => 'null 2', 51 ), 52 53 // boolean data 54/*4*/ 'bool lowercase' => array( 55 true => 'lowert', 56 false => 'lowerf', 57 ), 58 'bool uppercase' => array( 59 TRUE => 'uppert', 60 FALSE => 'upperf', 61 ), 62 63 // empty data 64/*5*/ 'empty double quotes' => array( 65 "" => 'emptyd', 66 ), 67 'empty single quotes' => array( 68 '' => 'emptys', 69 ), 70 71 // string data 72/*6*/ 'string' => array( 73 "stringd" => 'stringd', 74 'strings' => 'strings', 75 $heredoc => 'stringh', 76 ), 77 78 // undefined data 79/*8*/ 'undefined' => array( 80 @$undefined_var => 'undefined', 81 ), 82 83 // unset data 84/*9*/ 'unset' => array( 85 @$unset_var => 'unset', 86 ), 87); 88 89// loop through each element of $inputs to check the behavior of array_key_exists() 90$iterator = 1; 91foreach($inputs as $type => $input) { 92 echo "\n-- Iteration $iterator: $type data --\n"; 93 94 //iterate over again to get all different key values 95 foreach ($inputs as $new_type => $new_input) { 96 echo "-- \$key arguments are $new_type data:\n"; 97 foreach ($new_input as $key => $search) { 98 var_dump(array_key_exists($key, $input)); 99 } 100 } 101 $iterator++; 102}; 103 104echo "Done"; 105?> 106--EXPECT-- 107*** Testing array_key_exists() : usage variations *** 108 109-- Iteration 1: int data -- 110-- $key arguments are int data: 111bool(true) 112bool(true) 113bool(true) 114bool(true) 115-- $key arguments are float data: 116bool(false) 117bool(false) 118bool(true) 119-- $key arguments are extreme floats data: 120bool(false) 121bool(true) 122-- $key arguments are null uppercase data: 123bool(false) 124-- $key arguments are null lowercase data: 125bool(false) 126-- $key arguments are bool lowercase data: 127bool(true) 128bool(true) 129-- $key arguments are bool uppercase data: 130bool(true) 131bool(true) 132-- $key arguments are empty double quotes data: 133bool(false) 134-- $key arguments are empty single quotes data: 135bool(false) 136-- $key arguments are string data: 137bool(false) 138bool(false) 139bool(false) 140-- $key arguments are undefined data: 141bool(false) 142-- $key arguments are unset data: 143bool(false) 144 145-- Iteration 2: float data -- 146-- $key arguments are int data: 147bool(true) 148bool(false) 149bool(false) 150bool(false) 151-- $key arguments are float data: 152bool(true) 153bool(true) 154bool(true) 155-- $key arguments are extreme floats data: 156bool(false) 157bool(true) 158-- $key arguments are null uppercase data: 159bool(false) 160-- $key arguments are null lowercase data: 161bool(false) 162-- $key arguments are bool lowercase data: 163bool(false) 164bool(true) 165-- $key arguments are bool uppercase data: 166bool(false) 167bool(true) 168-- $key arguments are empty double quotes data: 169bool(false) 170-- $key arguments are empty single quotes data: 171bool(false) 172-- $key arguments are string data: 173bool(false) 174bool(false) 175bool(false) 176-- $key arguments are undefined data: 177bool(false) 178-- $key arguments are unset data: 179bool(false) 180 181-- Iteration 3: extreme floats data -- 182-- $key arguments are int data: 183bool(true) 184bool(false) 185bool(false) 186bool(false) 187-- $key arguments are float data: 188bool(false) 189bool(false) 190bool(true) 191-- $key arguments are extreme floats data: 192bool(true) 193bool(true) 194-- $key arguments are null uppercase data: 195bool(false) 196-- $key arguments are null lowercase data: 197bool(false) 198-- $key arguments are bool lowercase data: 199bool(false) 200bool(true) 201-- $key arguments are bool uppercase data: 202bool(false) 203bool(true) 204-- $key arguments are empty double quotes data: 205bool(false) 206-- $key arguments are empty single quotes data: 207bool(false) 208-- $key arguments are string data: 209bool(false) 210bool(false) 211bool(false) 212-- $key arguments are undefined data: 213bool(false) 214-- $key arguments are unset data: 215bool(false) 216 217-- Iteration 4: null uppercase data -- 218-- $key arguments are int data: 219bool(false) 220bool(false) 221bool(false) 222bool(false) 223-- $key arguments are float data: 224bool(false) 225bool(false) 226bool(false) 227-- $key arguments are extreme floats data: 228bool(false) 229bool(false) 230-- $key arguments are null uppercase data: 231bool(true) 232-- $key arguments are null lowercase data: 233bool(true) 234-- $key arguments are bool lowercase data: 235bool(false) 236bool(false) 237-- $key arguments are bool uppercase data: 238bool(false) 239bool(false) 240-- $key arguments are empty double quotes data: 241bool(true) 242-- $key arguments are empty single quotes data: 243bool(true) 244-- $key arguments are string data: 245bool(false) 246bool(false) 247bool(false) 248-- $key arguments are undefined data: 249bool(true) 250-- $key arguments are unset data: 251bool(true) 252 253-- Iteration 5: null lowercase data -- 254-- $key arguments are int data: 255bool(false) 256bool(false) 257bool(false) 258bool(false) 259-- $key arguments are float data: 260bool(false) 261bool(false) 262bool(false) 263-- $key arguments are extreme floats data: 264bool(false) 265bool(false) 266-- $key arguments are null uppercase data: 267bool(true) 268-- $key arguments are null lowercase data: 269bool(true) 270-- $key arguments are bool lowercase data: 271bool(false) 272bool(false) 273-- $key arguments are bool uppercase data: 274bool(false) 275bool(false) 276-- $key arguments are empty double quotes data: 277bool(true) 278-- $key arguments are empty single quotes data: 279bool(true) 280-- $key arguments are string data: 281bool(false) 282bool(false) 283bool(false) 284-- $key arguments are undefined data: 285bool(true) 286-- $key arguments are unset data: 287bool(true) 288 289-- Iteration 6: bool lowercase data -- 290-- $key arguments are int data: 291bool(true) 292bool(true) 293bool(false) 294bool(false) 295-- $key arguments are float data: 296bool(false) 297bool(false) 298bool(true) 299-- $key arguments are extreme floats data: 300bool(false) 301bool(true) 302-- $key arguments are null uppercase data: 303bool(false) 304-- $key arguments are null lowercase data: 305bool(false) 306-- $key arguments are bool lowercase data: 307bool(true) 308bool(true) 309-- $key arguments are bool uppercase data: 310bool(true) 311bool(true) 312-- $key arguments are empty double quotes data: 313bool(false) 314-- $key arguments are empty single quotes data: 315bool(false) 316-- $key arguments are string data: 317bool(false) 318bool(false) 319bool(false) 320-- $key arguments are undefined data: 321bool(false) 322-- $key arguments are unset data: 323bool(false) 324 325-- Iteration 7: bool uppercase data -- 326-- $key arguments are int data: 327bool(true) 328bool(true) 329bool(false) 330bool(false) 331-- $key arguments are float data: 332bool(false) 333bool(false) 334bool(true) 335-- $key arguments are extreme floats data: 336bool(false) 337bool(true) 338-- $key arguments are null uppercase data: 339bool(false) 340-- $key arguments are null lowercase data: 341bool(false) 342-- $key arguments are bool lowercase data: 343bool(true) 344bool(true) 345-- $key arguments are bool uppercase data: 346bool(true) 347bool(true) 348-- $key arguments are empty double quotes data: 349bool(false) 350-- $key arguments are empty single quotes data: 351bool(false) 352-- $key arguments are string data: 353bool(false) 354bool(false) 355bool(false) 356-- $key arguments are undefined data: 357bool(false) 358-- $key arguments are unset data: 359bool(false) 360 361-- Iteration 8: empty double quotes data -- 362-- $key arguments are int data: 363bool(false) 364bool(false) 365bool(false) 366bool(false) 367-- $key arguments are float data: 368bool(false) 369bool(false) 370bool(false) 371-- $key arguments are extreme floats data: 372bool(false) 373bool(false) 374-- $key arguments are null uppercase data: 375bool(true) 376-- $key arguments are null lowercase data: 377bool(true) 378-- $key arguments are bool lowercase data: 379bool(false) 380bool(false) 381-- $key arguments are bool uppercase data: 382bool(false) 383bool(false) 384-- $key arguments are empty double quotes data: 385bool(true) 386-- $key arguments are empty single quotes data: 387bool(true) 388-- $key arguments are string data: 389bool(false) 390bool(false) 391bool(false) 392-- $key arguments are undefined data: 393bool(true) 394-- $key arguments are unset data: 395bool(true) 396 397-- Iteration 9: empty single quotes data -- 398-- $key arguments are int data: 399bool(false) 400bool(false) 401bool(false) 402bool(false) 403-- $key arguments are float data: 404bool(false) 405bool(false) 406bool(false) 407-- $key arguments are extreme floats data: 408bool(false) 409bool(false) 410-- $key arguments are null uppercase data: 411bool(true) 412-- $key arguments are null lowercase data: 413bool(true) 414-- $key arguments are bool lowercase data: 415bool(false) 416bool(false) 417-- $key arguments are bool uppercase data: 418bool(false) 419bool(false) 420-- $key arguments are empty double quotes data: 421bool(true) 422-- $key arguments are empty single quotes data: 423bool(true) 424-- $key arguments are string data: 425bool(false) 426bool(false) 427bool(false) 428-- $key arguments are undefined data: 429bool(true) 430-- $key arguments are unset data: 431bool(true) 432 433-- Iteration 10: string data -- 434-- $key arguments are int data: 435bool(false) 436bool(false) 437bool(false) 438bool(false) 439-- $key arguments are float data: 440bool(false) 441bool(false) 442bool(false) 443-- $key arguments are extreme floats data: 444bool(false) 445bool(false) 446-- $key arguments are null uppercase data: 447bool(false) 448-- $key arguments are null lowercase data: 449bool(false) 450-- $key arguments are bool lowercase data: 451bool(false) 452bool(false) 453-- $key arguments are bool uppercase data: 454bool(false) 455bool(false) 456-- $key arguments are empty double quotes data: 457bool(false) 458-- $key arguments are empty single quotes data: 459bool(false) 460-- $key arguments are string data: 461bool(true) 462bool(true) 463bool(true) 464-- $key arguments are undefined data: 465bool(false) 466-- $key arguments are unset data: 467bool(false) 468 469-- Iteration 11: undefined data -- 470-- $key arguments are int data: 471bool(false) 472bool(false) 473bool(false) 474bool(false) 475-- $key arguments are float data: 476bool(false) 477bool(false) 478bool(false) 479-- $key arguments are extreme floats data: 480bool(false) 481bool(false) 482-- $key arguments are null uppercase data: 483bool(true) 484-- $key arguments are null lowercase data: 485bool(true) 486-- $key arguments are bool lowercase data: 487bool(false) 488bool(false) 489-- $key arguments are bool uppercase data: 490bool(false) 491bool(false) 492-- $key arguments are empty double quotes data: 493bool(true) 494-- $key arguments are empty single quotes data: 495bool(true) 496-- $key arguments are string data: 497bool(false) 498bool(false) 499bool(false) 500-- $key arguments are undefined data: 501bool(true) 502-- $key arguments are unset data: 503bool(true) 504 505-- Iteration 12: unset data -- 506-- $key arguments are int data: 507bool(false) 508bool(false) 509bool(false) 510bool(false) 511-- $key arguments are float data: 512bool(false) 513bool(false) 514bool(false) 515-- $key arguments are extreme floats data: 516bool(false) 517bool(false) 518-- $key arguments are null uppercase data: 519bool(true) 520-- $key arguments are null lowercase data: 521bool(true) 522-- $key arguments are bool lowercase data: 523bool(false) 524bool(false) 525-- $key arguments are bool uppercase data: 526bool(false) 527bool(false) 528-- $key arguments are empty double quotes data: 529bool(true) 530-- $key arguments are empty single quotes data: 531bool(true) 532-- $key arguments are string data: 533bool(false) 534bool(false) 535bool(false) 536-- $key arguments are undefined data: 537bool(true) 538-- $key arguments are unset data: 539bool(true) 540Done 541