import zend standard tests
[hiphop-php.git] / hphp / test / zend / good / ext-standard-array / in_array_variation4.php
blobfab3148fa8d106b1458456a15328763d265a44af
1 <?php
2 /*
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
7 */
9 /* Test in_array() with haystack as resouce and multidimentional arrays */
11 /* checking for Resources */
12 echo "*** Testing resource type with in_array() ***\n";
13 //file type resource
14 $file_handle = fopen(__FILE__, "r");
16 //directory type resource
17 $dir_handle = opendir( dirname(__FILE__) );
19 //store resources in array for comparision.
20 $resources = array($file_handle, $dir_handle);
22 // search for resouce type in the resource array
23 var_dump( in_array($file_handle, $resources, true) );
24 //checking for (int) type resource
25 var_dump( in_array((int)$dir_handle, $resources, true) );
27 /* Miscellenous input check */
28 echo "\n*** Testing miscelleneos inputs with in_array() ***\n";
29 //matching "Good" in array(0,"hello"), result:true in loose type check
30 var_dump( in_array("Good", array(0,"hello")) );
31 //false in strict mode
32 var_dump( in_array("Good", array(0,"hello"), TRUE) );
34 //matching integer 0 in array("this"), result:true in loose type check
35 var_dump( in_array(0, array("this")) );
36 // false in strict mode
37 var_dump( in_array(0, array("this")),TRUE );
39 //matching string "this" in array(0), result:true in loose type check
40 var_dump( in_array("this", array(0)) );
41 // false in stric mode
42 var_dump( in_array("this", array(0), TRUE) );
44 //checking for type FALSE in multidimensional array with loose checking, result:false in loose type check
45 var_dump( in_array(FALSE,
46 array("a"=> TRUE, "b"=> TRUE,
47 array("c"=> TRUE, "d"=>TRUE)
50 );
52 //matching string having integer in beginning, result:true in loose type check
53 var_dump( in_array('123abc', array(123)) );
54 var_dump( in_array('123abc', array(123), TRUE) ); // false in strict mode
56 echo "Done\n";