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