yes, I thought about that ... already 😉
We need to delete a used value from $first_arr
When removing one element in an array (or any other variable),
we use the function [man]unset[/man]
unset( $first_arr[0] );
will remove: [0] => 10
which is the first pair
'key' =>value
in this array
like this, I use a variable $key to store each random result
this holds the 'key' number to an element in $first_array
<?php
//another way to assign this array would be
//$first_arr = array( 10,20,30,40,50,60,70,80,90,100 );
//but lets use your automatic way
for( $counter = 10; $counter <= 100; $counter += 10 ) {
echo $counter.", ";
//will make $first_arr[0]=10, $first_arr[1]=20, etc etc
$first_arr[] = $counter;
}
//show contents of this first array
//echo '<pre>'. print_r( $first_arr, true ). '</pre>';
$num = 5; // loop 5 times
for( $i=0; $i<5 ; $i++ ){
// we use special function, array_rand(), to get one value of $first_arr
// pick a random value of all in first_arr
$key = array_rand($first_arr);
$rand_arr[] = $first_arr[$key];
unset( $first_arr[$key] );
//array_rand returns 0-9, which is one 'key' of $first_arr
//we put that key, e.g. 1, to adress $first_arr[1], which is the value '20'
}
// we can see how much is left of $first_arr, not used values
echo '<pre>'. print_r( $first_arr, true ). '</pre>';
echo '<hr>'; ///////////
// show contents of this new array
echo 'new array:';
echo '<pre>'. print_r( $rand_arr, true ). '</pre>';
sort($rand_arr);
echo 'sorted:';
echo '<pre>'. print_r( $rand_arr, true ). '</pre>';
exit( '<a href="">Do it Again</a>' );
?>