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