Bisix

chunknshuffle

Jun 17th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.30 KB | None | 0 0
  1. $shuffled = [];
  2. $alphas = range('a', 'z'); // [a, ...z]
  3. $pattern = [1, 2, 0];
  4.  
  5. foreach (array_chunk($alphas, 3) as $chk) {
  6.     $r = [];
  7.     foreach ($pattern as $i => $_) {
  8.         $r[$i] = $chk[$pattern[$i]] ?? '';
  9.     }
  10.     array_push($shuffled, ...$r);
  11. }
  12.  
  13. print_r(json_encode($shuffled));
Advertisement
Add Comment
Please, Sign In to add comment