fork download
  1. <?php
  2.  
  3. $names = array(
  4. 'bill',
  5. 'steve',
  6. 'Ritchie',
  7. 'Ritchie',
  8. 'will',
  9. 'bill',
  10. );
  11. $countries = array(
  12. 'USA',
  13. 'UK',
  14. 'Netherlands',
  15. 'Australia',
  16. 'Germany',
  17. );
  18.  
  19. shuffle($countries);
  20. $n = count($countries); $i = 0;
  21. $jumble = array();
  22. foreach ($names as $name) {
  23. if (!isset($jumble[$name])) $jumble[$name] = array();
  24. $jumble[$name][] = $countries[$i++ % $n];
  25. }
  26.  
  27. print_r($jumble);
  28.  
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Array
(
    [bill] => Array
        (
            [0] => USA
            [1] => USA
        )

    [steve] => Array
        (
            [0] => Australia
        )

    [Ritchie] => Array
        (
            [0] => Netherlands
            [1] => Germany
        )

    [will] => Array
        (
            [0] => UK
        )

)