If you want to circularly assign the phone numbers to the users, Simply iterate the over each mobile number, get its index, find the equivalent index in the $users
array by finding the remainder of the index with the size of the $users
array. You can find the remainder using the Modulus(%
) operator.
Try this -
$users = Array(2,5,6,7,8,9,10,11,12);
$mob = Array(1234567890,2345678901,3456789012,4567890123,5678901234,6789012345,7890123456,8901234567,9012345678,9901234567,1234567890,2345678901,3456789012);
$res = Array();
$user_size = count($users);
//The main logic.
foreach($mob as $k=>$v){
$res[ $users[$k % $user_size] ][] = $v;
}
var_dump($res);
/** OUTPUT
array
2 =>
array
0 => int 1234567890
1 => float 9901234567
5 =>
array
0 => float 2345678901
1 => int 1234567890
6 =>
array
0 => float 3456789012
1 => float 2345678901
7 =>
array
0 => float 4567890123
1 => float 3456789012
8 =>
array
0 => float 5678901234
9 =>
array
0 => float 6789012345
10 =>
array
0 => float 7890123456
11 =>
array
0 => float 8901234567
12 =>
array
0 => float 9012345678