我有2个数组$projectsIds = [1,2]
和$usersIds = [1,2,3]
我有这样的foreach循环:
foreach($projectsIds as $projecID){
foreach($userIds as $userID){
$sync_array[$projecID] = array('user_id' => $userID);
}
}
dd($sync_array);
现在我得到这样的结果:
array:2 [ 1 => array:1 [ "user_id" => 1 ]
2 => array:1 [ "user_id" => 1 ]
]
可以得到这样的结果:
array:2 [ 1 => array:1 [ "user_id" => 1 ]
1 => array:1 [ "user_id" => 2 ]
1 => array:1 [ "user_id" => 3 ]
2 => array:1 [ "user_id" => 1 ]
2 => array:1 [ "user_id" => 2 ]
2 => array:1 [ "user_id" => 3 ]
]