1--TEST--
2Test 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
13echo "*** 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;
39foreach($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
50echo "Done\n";
51?>
52--EXPECTF--
53*** Testing array_search() with different haystack values ***
54-- Iteration 1 --
55int(0)
56int(3)
57int(0)
58-- Iteration 2 --
59string(1) "y"
60int(4)
61string(1) "y"
62-- Iteration 3 --
63int(3)
64bool(false)
65int(3)
66-- Iteration 4 --
67string(3) "key"
68int(2)
69string(3) "key"
70-- Iteration 5 --
71int(3)
72bool(false)
73int(3)
74-- Iteration 6 --
75int(3)
76bool(false)
77int(3)
78-- Iteration 7 --
79int(2)
80bool(false)
81int(2)
82-- Iteration 8 --
83int(3)
84bool(false)
85int(3)
86-- Iteration 9 --
87string(1) "y"
88string(1) "y"
89string(1) "y"
90-- Iteration 10 --
91string(1) "y"
92bool(false)
93string(1) "y"
94-- Iteration 11 --
95int(2)
96bool(false)
97int(2)
98-- Iteration 12 --
99string(1) "y"
100string(0) ""
101string(1) "y"
102Done
103