Annotation of embedaddon/php/ext/standard/tests/array/array_search_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_search() function : usage variations - different haystack values
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: /* Test array_search() with different possible haystack values */
12:
13: echo "*** Testing array_search() with different haystack values ***\n";
14:
15: $misc_array = array (
16: 'a',
17: 'key' =>'d',
18: 3,
19: ".001" =>-67,
20: "-.051" =>"k",
21: 0.091 =>"-.08",
22: "e" =>"5",
23: "y" =>NULL,
24: NULL =>"",
25: 0,
26: TRUE,
27: FALSE,
28: -27.39999999999,
29: " ",
30: "abcd\x00abcd\x00\abcd\x00abcdefghij",
31: "abcd\nabcd\tabcd\rabcd\0abcd"
32: );
33: $array_type = array(TRUE, FALSE, 1, 0, -1, "1", "0", "-1", NULL, array(), "PHP", "");
34: /* loop to do loose and strict type check of elements in
35: $array_type on elements in $misc_array using array_search();
36: checking PHP type comparison tables
37: */
38: $counter = 1;
39: foreach($array_type as $type) {
40: echo "-- Iteration $counter --\n";
41: //loose type checking
42: var_dump( array_search($type,$misc_array ) );
43: //strict type checking
44: var_dump( array_search($type,$misc_array,true) );
45: //loose type checking
46: var_dump( array_search($type,$misc_array,false) );
47: $counter++;
48: }
49:
50: echo "Done\n";
51: ?>
52: --EXPECTF--
53: *** Testing array_search() with different haystack values ***
54: -- Iteration 1 --
55: int(0)
56: int(3)
57: int(0)
58: -- Iteration 2 --
59: string(1) "y"
60: int(4)
61: string(1) "y"
62: -- Iteration 3 --
63: int(3)
64: bool(false)
65: int(3)
66: -- Iteration 4 --
67: string(3) "key"
68: int(2)
69: string(3) "key"
70: -- Iteration 5 --
71: int(3)
72: bool(false)
73: int(3)
74: -- Iteration 6 --
75: int(3)
76: bool(false)
77: int(3)
78: -- Iteration 7 --
79: int(2)
80: bool(false)
81: int(2)
82: -- Iteration 8 --
83: int(3)
84: bool(false)
85: int(3)
86: -- Iteration 9 --
87: string(1) "y"
88: string(1) "y"
89: string(1) "y"
90: -- Iteration 10 --
91: string(1) "y"
92: bool(false)
93: string(1) "y"
94: -- Iteration 11 --
95: int(2)
96: bool(false)
97: int(2)
98: -- Iteration 12 --
99: string(1) "y"
100: string(0) ""
101: string(1) "y"
102: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>