fork download
  1. <?php
  2. $array = array(2, 2, 1, 3, 3, 3, 4, 4, 5, 5, 6);
  3.  
  4. for ($j = 0; $j < 5; $j++){
  5. $nuevo = array();
  6. $nuevo[] = $array[array_rand($array)];
  7. $i = 1;
  8. while ($i < 3)
  9. if (!in_array($aux = $array[array_rand($array)], $nuevo)){
  10. $nuevo[] = $aux;
  11. $i++;
  12. }
  13. echo implode(', ', $nuevo) . "\n";
  14. }
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
3, 4, 5
6, 4, 3
3, 4, 5
3, 5, 2
3, 4, 6