title: get random value from a PHP array, but make it unique
body: <p>I want to select a random value from a array, but keep it unique as long as possible.</p>
  
  <p>For example if I'm selecting a value 4 times from a array of 4 elements, the selected value should be random, but different every time.</p>
  
  <p>If I'm selecting it 10 times from the same array of 4 elements, then obviously some values will be duplicated.</p>
  
  <p>I have this right now, but I still get duplicate values, even if the loop is running 4 times:</p>
  
  <pre><code>$arr = $arr_history = ('abc', 'def', 'xyz', 'qqq');
  
  for($i = 1; $i &lt; 5; $i++){
    if(empty($arr_history)) $arr_history = $arr; 
    $selected = $arr_history[array_rand($arr_history, 1)];  
    unset($arr_history[$selected]); 
    // do something with $selected here...
  }
  </code></pre>