1--TEST--
2Test array_key_exists() function : usage variations -  equality test for certain data types
3--FILE--
4<?php
5/* Prototype  : bool array_key_exists(mixed $key, array $search)
6 * Description: Checks if the given key or index exists in the array
7 * Source code: ext/standard/array.c
8 * Alias to functions: key_exists
9 */
10
11/*
12 * Pass certain data types that can be taken as a key in an array
13 * and test whether array_key_exists(() thinks they are equal and therefore
14 * returns true when searching for them
15 */
16
17echo "*** Testing array_key_exists() : usage variations ***\n";
18
19$unset = 10;
20unset($unset);
21$array = array ('null' => null,
22                'NULL' => NULL,
23                'empty single quoted string' => '',
24                "empty double quoted string" => "",
25                'undefined variable' => @$undefined,
26                'unset variable' => @$unset);
27
28//iterate through original array
29foreach($array as $name => $input) {
30	$iterator = 1;
31	echo "\n-- Key in \$search array is : $name --\n";
32	$search[$input] = 'test';
33
34	//iterate through array again to see which values are considered equal
35	foreach($array as $key) {
36		echo "Iteration $iterator:  ";
37		var_dump(array_key_exists($key, $search));
38		$iterator++;
39	}
40	$search = null;
41}
42
43echo "Done";
44?>
45
46--EXPECTF--
47*** Testing array_key_exists() : usage variations ***
48
49-- Key in $search array is : null --
50Iteration 1:  bool(true)
51Iteration 2:  bool(true)
52Iteration 3:  bool(true)
53Iteration 4:  bool(true)
54Iteration 5:  bool(true)
55Iteration 6:  bool(true)
56
57-- Key in $search array is : NULL --
58Iteration 1:  bool(true)
59Iteration 2:  bool(true)
60Iteration 3:  bool(true)
61Iteration 4:  bool(true)
62Iteration 5:  bool(true)
63Iteration 6:  bool(true)
64
65-- Key in $search array is : empty single quoted string --
66Iteration 1:  bool(true)
67Iteration 2:  bool(true)
68Iteration 3:  bool(true)
69Iteration 4:  bool(true)
70Iteration 5:  bool(true)
71Iteration 6:  bool(true)
72
73-- Key in $search array is : empty double quoted string --
74Iteration 1:  bool(true)
75Iteration 2:  bool(true)
76Iteration 3:  bool(true)
77Iteration 4:  bool(true)
78Iteration 5:  bool(true)
79Iteration 6:  bool(true)
80
81-- Key in $search array is : undefined variable --
82Iteration 1:  bool(true)
83Iteration 2:  bool(true)
84Iteration 3:  bool(true)
85Iteration 4:  bool(true)
86Iteration 5:  bool(true)
87Iteration 6:  bool(true)
88
89-- Key in $search array is : unset variable --
90Iteration 1:  bool(true)
91Iteration 2:  bool(true)
92Iteration 3:  bool(true)
93Iteration 4:  bool(true)
94Iteration 5:  bool(true)
95Iteration 6:  bool(true)
96Done