我想在for-each循环或你建议的任何其他方式循环数组变量。当循环时,如果一个数组有两个或多个相同的项/值,循环应跳过数据并继续下一个数据。
$users = array ( array('user1', id , email),
array('user2', id , email),
array('user3', id , email),
array('user4', id , email)
foreach ($users as $key) {
// do something for each user
// if from arrays user1 , user2 , user3 , user4 there are some identical data ..
// skip that user and continue with another user
// then return results and number of users skipped
}
示例: if in array $ users user1的电子邮件地址/ id与user3相同,跳过user3并继续user4
希望你有我的观点,因为我的英语不太好
答案 0 :(得分:0)
一种简单的方法就是将当前出现的所有电子邮件地址放入另一个数组中,然后检查当前的电子邮件是否已经存在:
$email_addresses_processed_so_far = array();
foreach ($users as $key) {
if(in_array($key[2], $email_addresses_processed_so_far)) {
continue;
}
$email_addresses_processed_so_far[] = $key[2]; // put email address into array
// additional processing here
// …
}