1--TEST--
2Test array_search() function : usage variations - haystack as sub-array/object
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 sub-arrays with array_search() */
12echo "*** Testing sub-arrays with array_search() ***\n";
13$sub_array = array (
14  "one",
15  array(1, 2 => "two", "three" => 3),
16  4 => "four",
17  "five" => 5,
18  array('', 'i')
19);
20var_dump( array_search("four", $sub_array) );
21//checking for element in a sub-array
22var_dump( array_search(3, $sub_array[1]) );
23var_dump( array_search(array('','i'), $sub_array) );
24
25/* checking for objects in array_search() */
26echo "\n*** Testing objects with array_search() ***\n";
27class array_search_check {
28  public $array_var = array(1=>"one", "two"=>2, 3=>3);
29  public function foo() {
30    echo "Public function\n";
31  }
32}
33
34$array_search_obj = new array_search_check();  //creating new object
35//error: as wrong datatype for second argument
36var_dump( array_search("array_var", $array_search_obj) );
37//error: as wrong datatype for second argument
38var_dump( array_search("foo", $array_search_obj) );
39//element found as "one" exists in array $array_var
40var_dump( array_search("one", $array_search_obj->array_var) );
41
42echo "Done\n";
43?>
44--EXPECTF--
45*** Testing sub-arrays with array_search() ***
46int(4)
47string(5) "three"
48int(5)
49
50*** Testing objects with array_search() ***
51
52Warning: array_search() expects parameter 2 to be array, object given in %s on line %d
53NULL
54
55Warning: array_search() expects parameter 2 to be array, object given in %s on line %d
56NULL
57int(1)
58Done
59