1--TEST--
2Test in_array() function : usage variations - different haystack values
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 different possible haystack values */
13
14echo "*** Testing in_array() with different haystack values ***\n";
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 in_array();
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( in_array($type,$misc_array ) );
43  //strict type checking
44  var_dump( in_array($type,$misc_array,true) );
45  //loose type checking
46  var_dump( in_array($type,$misc_array,false) );
47  $counter++;
48}
49
50echo "Done\n";
51?>
52--EXPECT--
53*** Testing in_array() with different haystack values ***
54-- Iteration 1 --
55bool(true)
56bool(true)
57bool(true)
58-- Iteration 2 --
59bool(true)
60bool(true)
61bool(true)
62-- Iteration 3 --
63bool(true)
64bool(false)
65bool(true)
66-- Iteration 4 --
67bool(true)
68bool(true)
69bool(true)
70-- Iteration 5 --
71bool(true)
72bool(false)
73bool(true)
74-- Iteration 6 --
75bool(true)
76bool(false)
77bool(true)
78-- Iteration 7 --
79bool(true)
80bool(false)
81bool(true)
82-- Iteration 8 --
83bool(true)
84bool(false)
85bool(true)
86-- Iteration 9 --
87bool(true)
88bool(true)
89bool(true)
90-- Iteration 10 --
91bool(true)
92bool(false)
93bool(true)
94-- Iteration 11 --
95bool(true)
96bool(false)
97bool(true)
98-- Iteration 12 --
99bool(true)
100bool(true)
101bool(true)
102Done
103