3 * Prototype : bool in_array ( mixed $needle, array $haystack [, bool $strict] )
4 * Description: Searches haystack for needle and returns TRUE
5 * if it is found in the array, FALSE otherwise.
6 * Source Code: ext/standard/array.c
9 /* Test in_array() with haystack as sub-array and object */
11 /* checking for sub-arrays with in_array() */
12 echo "*** Testing sub-arrays with in_array() ***\n";
15 array(1, 2 => "two", "three" => 3),
20 var_dump( in_array("four", $sub_array) );
21 //checking for element in a sub-array
22 var_dump( in_array(3, $sub_array[1]) );
23 var_dump( in_array(array('','i'), $sub_array) );
25 /* checking for objects in in_array() */
26 echo "\n*** Testing objects with in_array() ***\n";
27 class in_array_check
{
28 public $array_var = array(1=>"one", "two"=>2, 3=>3);
29 public function foo() {
30 echo "Public function\n";
34 $in_array_obj = new in_array_check(); //creating new object
35 //error: as wrong datatype for second argument
36 var_dump( in_array("array_var", $in_array_obj) );
37 //error: as wrong datatype for second argument
38 var_dump( in_array("foo", $in_array_obj) );
39 //element found as "one" exists in array $array_var
40 var_dump( in_array("one", $in_array_obj->array_var
) );