1--TEST--
2Test array_search() function : usage variations - haystack as resource/multi dimensional array
3--FILE--
4<?php
5/* checking for Resources */
6echo "*** Testing resource type with array_search() ***\n";
7//file type resource
8$file_handle = fopen(__FILE__, "r");
9
10//directory type resource
11$dir_handle = opendir( __DIR__ );
12
13//store resources in array for comparison.
14$resources = array($file_handle, $dir_handle);
15
16// search for resource type in the resource array
17var_dump( array_search($file_handle, $resources, true) );
18//checking for (int) type resource
19var_dump( array_search((int)$dir_handle, $resources, true) );
20
21/* Miscellenous input check  */
22echo "\n*** Testing miscelleneos inputs with array_search() ***\n";
23//matching "Good" in array(0,"hello"), result:true in loose type check
24var_dump( array_search("Good", array(0,"hello")) );
25//false in strict mode
26var_dump( array_search("Good", array(0,"hello"), TRUE) );
27
28//matching integer 0 in array("this"), result:true in loose type check
29var_dump( array_search(0, array("this")) );
30// false in strict mode
31var_dump( array_search(0, array("this")),TRUE );
32
33//matching string "this" in array(0), result:true in loose type check
34var_dump( array_search("this", array(0)) );
35// false in stric mode
36var_dump( array_search("this", array(0), TRUE) );
37
38//checking for type FALSE in multidimensional array with loose checking, result:false in loose type check
39var_dump( array_search(FALSE,
40                   array("a"=> TRUE, "b"=> TRUE,
41                         array("c"=> TRUE, "d"=>TRUE)
42                        )
43                  )
44        );
45
46//matching string having integer in beginning, result:true in loose type check
47var_dump( array_search('123abc', array(123)) );
48var_dump( array_search('123abc', array(123), TRUE) ); // false in strict mode
49
50echo "Done\n";
51?>
52--EXPECT--
53*** Testing resource type with array_search() ***
54int(0)
55bool(false)
56
57*** Testing miscelleneos inputs with array_search() ***
58bool(false)
59bool(false)
60bool(false)
61bool(false)
62bool(true)
63bool(false)
64bool(false)
65bool(false)
66bool(false)
67bool(false)
68Done
69