import zend standard tests
[hiphop-php.git] / hphp / test / zend / good / ext-standard-array / array_search_variation4.php
blobcbc1b7c277510608dd1c0670b674027df8e2eb8c
1 <?php
2 /*
3 * Prototype : mixed array_search ( mixed $needle, array $haystack [, bool $strict] )
4 * Description: Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise
5 * Source Code: ext/standard/array.c
6 */
8 /* checking for Resources */
9 echo "*** Testing resource type with array_search() ***\n";
10 //file type resource
11 $file_handle = fopen(__FILE__, "r");
13 //directory type resource
14 $dir_handle = opendir( dirname(__FILE__) );
16 //store resources in array for comparision.
17 $resources = array($file_handle, $dir_handle);
19 // search for resouce type in the resource array
20 var_dump( array_search($file_handle, $resources, true) );
21 //checking for (int) type resource
22 var_dump( array_search((int)$dir_handle, $resources, true) );
24 /* Miscellenous input check */
25 echo "\n*** Testing miscelleneos inputs with array_search() ***\n";
26 //matching "Good" in array(0,"hello"), result:true in loose type check
27 var_dump( array_search("Good", array(0,"hello")) );
28 //false in strict mode
29 var_dump( array_search("Good", array(0,"hello"), TRUE) );
31 //matching integer 0 in array("this"), result:true in loose type check
32 var_dump( array_search(0, array("this")) );
33 // false in strict mode
34 var_dump( array_search(0, array("this")),TRUE );
36 //matching string "this" in array(0), result:true in loose type check
37 var_dump( array_search("this", array(0)) );
38 // false in stric mode
39 var_dump( array_search("this", array(0), TRUE) );
41 //checking for type FALSE in multidimensional array with loose checking, result:false in loose type check
42 var_dump( array_search(FALSE,
43 array("a"=> TRUE, "b"=> TRUE,
44 array("c"=> TRUE, "d"=>TRUE)
47 );
49 //matching string having integer in beginning, result:true in loose type check
50 var_dump( array_search('123abc', array(123)) );
51 var_dump( array_search('123abc', array(123), TRUE) ); // false in strict mode
53 echo "Done\n";