在两个php数组中具有唯一值的唯一用户


Unique user having unique values in two php arrays

我将直接转到查询。我有一个html表单,它有两个字段(电子邮件和数字id)向每个用户询问。每一行中的两个值可以不同,也可以完全相同。该表单是动态的,根据要求要求要求提供多封电子邮件和数字ID。这两个值都被处理为php数组(电子邮件数组和数字数组)。我请求你们所有人帮助我完成查询,以找出具有唯一电子邮件的唯一ROW,并且关联的数值在整个数组中也应该是唯一的。

请帮帮我,这对我来说太重要了。提前Thanx。形成以下示例:

1.电子邮件-1编号-12.电子邮件-2编号-23.电子邮件-3编号-34.电子邮件-4编号-45.电子邮件-2编号-16.电子邮件-4编号-17.电子邮件-5编号-58.电子邮件-2编号-1
现在,我们必须查找唯一的一行或多行。。。这些输入可以是数百。

这就是我将数组值显示到下一页的方式-

<?php foreach($BX_EMAIL as $a=>$b){ ?>
<?php echo $a+1; ?>
<?php echo $BX_EMAIL[$a]; ?>
<?php echo $BX_NUM[$a]; ?>
<?php } ?>

现在,该页面之后的预期输出页面只是显示唯一的行(具有关联的唯一编号的唯一电子邮件)。

样本输入-

1.abc@pqr.com100002.pqr@abc.com112233.rst@hpq.com100004.tps@lkc.com909095.pqr@abc.com909096.wps@gps.com112237.tts@pps.com889978.abc@pqr.com112239wps@gps.com1000010.tts@lpg.com78789

现在,上面输入的输出应该是-
根据手动检查,由于只有10行,结果如下-

abc@pqr.com10000abc@pqr.com11223wps@gps.com10000rst@hpq.com10000wps@gps.com11223pqr@abc.com11223pqr@abc.com90909tps@lkc.com90909*********************tts@lpg.com78789*********************tts@pps.com88997

现在在上面的输出中有三个组——第一组是相同的,因为彼此中有相同的NUM和EMAIL,这使得记录相同。然而,第二组和第三组在任何地方都没有任何记录。这是我要求的预期分离输出。

我希望这次我已经足够清楚了。现在请根据情况多考虑一下。

根据您提供的信息,我认为这个解决方案已经足够了:

// ok - this is a reproduction of the two arrays you've got
$BX_EMAIL = array("1@domain.com", "2@domain.com", "3@domain.com", "2@domain.com");
$BX_NUM = array(1,2,3,2);
// merge the two arrays into two-dimensional array
$BX = array();
for($i = 0; $i < count($BX_EMAIL); $i++) 
    $BX[] = array($BX_EMAIL[$i], $BX_NUM[$i]);
// generate one-dimensional array of byte stream values
$bs = array_map("serialize", $BX);
//get unique values
$bs_unique = array_unique($bs);
// revert back to two-dimensional array
$result = array_map("unserialize", $bs_unique);
var_dump($result);

更新根据编辑的问题修改

// ok - this is a reproduction of the two arrays you've got
$BX_EMAIL = array(
    "abc@pqr.com", "pqr@abc.com", "rst@hpq.com", "tps@lkc.com", 
    "pqr@abc.com","wps@gps.com", "tts@pps.com",
    "abc@pqr.com", "wps@gps.com","tts@lpg.com");
$BX_NUM = array(10000,11223,10000,90909,90909,11223,88997,11223,10000,78789);
// create two-dimensional array
$BX = array();
for($i = 0; $i < count($BX_EMAIL); $i++) 
    $BX[] = array($BX_EMAIL[$i], $BX_NUM[$i]);
// find occurrences for each array
$occurrences_email = array_count_values($BX_EMAIL);
$occurrences_num = array_count_values($BX_NUM);
//filter BX on email and number only occurring once
$result = array_filter($BX, function($value) use(&$occurrences_email, &$occurrences_num) {
    return $occurrences_email[$value[0]] == 1 && $occurrences_num[$value[1]] == 1;
});
var_dump($result);

$BX的密钥仍然保留,因此您可能需要重置密钥:

$result = array_values($result);