Here's one way to sample 5 elements from an array without replacement in PHP:
main.php417 chars15 lines
This code uses the array_rand()
function to randomly select 5 keys from the array without replacement. It then loops through the selected keys, adds the corresponding values to the $sample
array, and prints it out.
gistlibby LogSnag