I have a array as following
array(
0 => array('email' => 'abc@abc.com','name'=>'abc'),
1 => array('email' => 'xyz@abc.com','name'=>'xyz'),
2 => array('email' => 'uvw@abc.com','name'=>'uvw'),
3 => array('email' => 'abc@abc.com','name'=>'str'),
)
I want to filter out records on email address and get records having same email address. For example from above example I want
array(
0 => array(
array(
0 => array('email' => 'abc@abc.com','name'=>'abc'),
1 => array('email' => 'abc@abc.com','name'=>'str'),
)
)
My code is
$tmpArray = array();
$duplicateRecords = array();
if (empty($data)) {
return false;
}
foreach ($data as $key => $value) {
if (in_array($value['Email'], $tmpArray)) {
$duplicateRecords[] = $value;
}
$tmpArray[] = $value['Email'];
}
echo '<pre>';print_r($duplicateRecords);die;
But this piece of code only returns the record's once existance, which is of second time. I know when It is traversing first time it isn't having email to compare. Is there any way to get existence of record as many times as it is in array.