Annotation of embedaddon/php/ext/standard/tests/array/in_array_variation4.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test 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 */
15: echo "*** 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:
1.1.1.2 ! misho 22: //store resources in array for comparison.
1.1 misho 23: $resources = array($file_handle, $dir_handle);
24:
25: // search for resouce type in the resource array
26: var_dump( in_array($file_handle, $resources, true) );
27: //checking for (int) type resource
28: var_dump( in_array((int)$dir_handle, $resources, true) );
29:
30: /* Miscellenous input check */
31: echo "\n*** Testing miscelleneos inputs with in_array() ***\n";
32: //matching "Good" in array(0,"hello"), result:true in loose type check
33: var_dump( in_array("Good", array(0,"hello")) );
34: //false in strict mode
35: var_dump( in_array("Good", array(0,"hello"), TRUE) );
36:
37: //matching integer 0 in array("this"), result:true in loose type check
38: var_dump( in_array(0, array("this")) );
39: // false in strict mode
40: var_dump( in_array(0, array("this")),TRUE );
41:
42: //matching string "this" in array(0), result:true in loose type check
43: var_dump( in_array("this", array(0)) );
44: // false in stric mode
45: var_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
48: var_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
56: var_dump( in_array('123abc', array(123)) );
57: var_dump( in_array('123abc', array(123), TRUE) ); // false in strict mode
58:
59: echo "Done\n";
60: ?>
61: --EXPECTF--
62: *** Testing resource type with in_array() ***
63: bool(true)
64: bool(false)
65:
66: *** Testing miscelleneos inputs with in_array() ***
67: bool(true)
68: bool(false)
69: bool(true)
70: bool(true)
71: bool(true)
72: bool(true)
73: bool(false)
74: bool(false)
75: bool(true)
76: bool(false)
77: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>