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
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.
15 function __toString() {
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
31 //array of values to iterate over
68 /*21*/ @$undefined_var,
74 // loop through each element of the array for different values for 'num_req' argument
76 foreach ($values as $value) {
77 echo "\n-- Iteration $count --\n";
79 var_dump(array_rand($input, $value));
80 } catch (Exception
$e) {
81 echo "\n".'Warning: '.$e->getMessage().' in '.__FILE__
.' on line '.__LINE__
."\n";