array_rand_basic1.phpt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. --TEST--
  2. Test array_rand() function : basic functionality - array with default keys
  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 array with default keys is passed to 'input' argument
  11. */
  12. echo "*** Testing array_rand() : array with default keys ***\n";
  13. // Initialise the 'input' and 'num_req' variables
  14. $input = array(10, 20, 30, 40, 50, 60, 70);
  15. $num_req = 6;
  16. // Calling array_rand() with optional argument
  17. echo"\n-- with all default and optional arguments --\n";
  18. var_dump( array_rand($input,$num_req) );
  19. // Calling array_rand() with default arguments
  20. echo"\n-- with default argument --\n";
  21. var_dump( array_rand($input) );
  22. echo "Done";
  23. ?>
  24. --EXPECTF--
  25. *** Testing array_rand() : array with default keys ***
  26. -- with all default and optional arguments --
  27. array(%d) {
  28. [0]=>
  29. int(%d)
  30. [1]=>
  31. int(%d)
  32. [2]=>
  33. int(%d)
  34. [3]=>
  35. int(%d)
  36. [4]=>
  37. int(%d)
  38. [5]=>
  39. int(%d)
  40. }
  41. -- with default argument --
  42. int(%d)
  43. Done