<?php
$ids = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110];
$users = [1,2,3,4,5];
// Temporary copy of users
$user_ids = [];
foreach( $ids as $id ){
// If our copy is empty, reload it
if(!$user_ids){
$user_ids = $users;
}
// Use array_shift() to grab and remove from the front
echo sprintf('%1$d - %2$d', $id, array_shift($user_ids)), PHP_EOL;
}
echo PHP_EOL;
foreach( $ids as $idx => $id ){
echo sprintf('%1$d - %2$d', $id, ($idx % 5) + 1 ), PHP_EOL;
}
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- 100 - 1
101 - 2
102 - 3
103 - 4
104 - 5
105 - 1
106 - 2
107 - 3
108 - 4
109 - 5
110 - 1
100 - 1
101 - 2
102 - 3
103 - 4
104 - 5
105 - 1
106 - 2
107 - 3
108 - 4
109 - 5
110 - 1
preferences:
124.68 ms | 407 KiB | 5 Q