array_rand_basic2.phpt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --TEST--
  2. Test array_rand() function : basic functionality - with associative array for 'input' argument
  3. --FILE--
  4. <?php
  5. /* Prototype : mixed array_rand(array $input [, int $num_req])
  6. * Description: Return key/keys for random entry/entries in the array
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Test array_rand() when associative array is passed to 'input' argument
  11. */
  12. echo "*** Testing array_rand() : with associative array ***\n";
  13. // Initialise the 'input' and 'num_req' variables
  14. $input = array(
  15. 'one' => 1, 'two' => 2, 'three' => 3,
  16. 'FoUr' => 'four', '#5' => 5, 'SIX' => 'six',
  17. "seven" => 7, "#8" => "eight", "nine" => "NINE"
  18. );
  19. $num_req = 6;
  20. // Calling array_rand() with optional argument
  21. echo"\n-- with all default and optional arguments --\n";
  22. var_dump( array_rand($input,$num_req) );
  23. // Calling array_rand() with default arguments
  24. echo"\n-- with default argument --\n";
  25. var_dump( array_rand($input) );
  26. echo "Done";
  27. ?>
  28. --EXPECTF--
  29. *** Testing array_rand() : with associative array ***
  30. -- with all default and optional arguments --
  31. array(6) {
  32. [0]=>
  33. string(%d) "%s"
  34. [1]=>
  35. string(%d) "%s"
  36. [2]=>
  37. string(%d) "%s"
  38. [3]=>
  39. string(%d) "%s"
  40. [4]=>
  41. string(%d) "%s"
  42. [5]=>
  43. string(%d) "%s"
  44. }
  45. -- with default argument --
  46. string(%d) "%s"
  47. Done