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