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--EXPECTF--
46*** Testing array_key_exists() : usage variations ***
47
48-- Key in $search array is : null --
49Iteration 1:  bool(true)
50Iteration 2:  bool(true)
51Iteration 3:  bool(true)
52Iteration 4:  bool(true)
53Iteration 5:  bool(true)
54Iteration 6:  bool(true)
55
56-- Key in $search array is : NULL --
57Iteration 1:  bool(true)
58Iteration 2:  bool(true)
59Iteration 3:  bool(true)
60Iteration 4:  bool(true)
61Iteration 5:  bool(true)
62Iteration 6:  bool(true)
63
64-- Key in $search array is : empty single quoted string --
65Iteration 1:  bool(true)
66Iteration 2:  bool(true)
67Iteration 3:  bool(true)
68Iteration 4:  bool(true)
69Iteration 5:  bool(true)
70Iteration 6:  bool(true)
71
72-- Key in $search array is : empty double quoted string --
73Iteration 1:  bool(true)
74Iteration 2:  bool(true)
75Iteration 3:  bool(true)
76Iteration 4:  bool(true)
77Iteration 5:  bool(true)
78Iteration 6:  bool(true)
79
80-- Key in $search array is : undefined variable --
81Iteration 1:  bool(true)
82Iteration 2:  bool(true)
83Iteration 3:  bool(true)
84Iteration 4:  bool(true)
85Iteration 5:  bool(true)
86Iteration 6:  bool(true)
87
88-- Key in $search array is : unset variable --
89Iteration 1:  bool(true)
90Iteration 2:  bool(true)
91Iteration 3:  bool(true)
92Iteration 4:  bool(true)
93Iteration 5:  bool(true)
94Iteration 6:  bool(true)
95Done
96