remove array_multisort and convert array_multisortN to use inout
[hiphop-php.git] / hphp / test / zend / good / ext / standard / tests / array / array_rand_variation2.php
blob0164688d8232099e14b744737c10bbb0388d9cf0
1 <?hh
2 /* Prototype : mixed array_rand(array input [, int num_req])
3 * Description: Return key/keys for random entry/entries in the array
4 * Source code: ext/standard/array.c
5 */
7 /*
8 * Test array_rand() with different types of values other than int passed to 'num_req' argument
9 * to see that function works with unexpeced data and generates warning message as required.
12 //define a class
13 class test {
14 public $t = 10;
15 function __toString() {
16 return "3object";
20 <<__EntryPoint>>
21 function main(): void {
22 echo "*** Testing array_rand() : unexpected values for 'num_req' parameter ***\n";
24 // Initialise function arguments
25 $input = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
27 //get an unset variable
28 $unset_var = 10;
29 unset($unset_var);
31 //array of values to iterate over
32 $values = array(
33 // int data
34 /*1*/ 0,
36 12345,
37 -2345,
39 // float data
40 /*5*/ 10.5,
41 -10.5,
42 12.3456789000e10,
43 12.3456789000E-10,
44 .5,
46 // null data
47 /*10*/ NULL,
48 null,
50 // boolean data
51 /*12*/ true,
52 false,
53 TRUE,
54 FALSE,
56 // empty data
57 /*16*/ "",
58 '',
60 // string data
61 /*18*/ "string",
62 'string',
64 // object data
65 /*20*/ new test(),
67 // undefined data
68 /*21*/ @$undefined_var,
70 // unset data
71 /*22*/ @$unset_var,
74 // loop through each element of the array for different values for 'num_req' argument
75 $count = 1;
76 foreach ($values as $value) {
77 echo "\n-- Iteration $count --\n";
78 try {
79 var_dump(array_rand($input, $value));
80 } catch (Exception $e) {
81 echo "\n".'Warning: '.$e->getMessage().' in '.__FILE__.' on line '.__LINE__."\n";
83 $count++;
86 echo "Done";