1--TEST--
2Test array_key_exists() function : usage variations - floats and casting to ints
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 floats as $key argument, then cast float values
13 * to integers and pass as $key argument
14 */
15
16echo "*** Testing array_key_exists() : usage variations ***\n";
17
18$keys = array(1.2345678900E-10, 1.00000000000001, 1.99999999999999);
19
20$search = array ('zero', 'one', 'two');
21
22$iterator = 1;
23foreach($keys as $key) {
24	echo "\n-- Iteration $iterator --\n";
25	echo "Pass float as \$key:\n";
26	var_dump(array_key_exists($key, $search));
27	echo "Cast float to int:\n";
28	var_dump(array_key_exists((int)$key, $search));
29}
30
31echo "Done";
32?>
33
34--EXPECTF--
35*** Testing array_key_exists() : usage variations ***
36
37-- Iteration 1 --
38Pass float as $key:
39
40Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
41bool(false)
42Cast float to int:
43bool(true)
44
45-- Iteration 1 --
46Pass float as $key:
47
48Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
49bool(false)
50Cast float to int:
51bool(true)
52
53-- Iteration 1 --
54Pass float as $key:
55
56Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d
57bool(false)
58Cast float to int:
59bool(true)
60Done