I have 2 arrays one contains just a list of email address and the other contains emails and names.
The list of emails in array1 are stored in a database and the other array is a list of new and current users.
I have tried using array_diff however this only seems to work if I specify in my loop that I just want emails.
$array1 = array(
0 => 'dave@daveshouse.com',
1 => 'sam@samshouse.com',
2 => 'jim@jimshouse.com',
3 => 'olly@ollyshouse.com',
4 => 'tom@tomshouse.com'
);
$array2 = array(
0 => array(
0 => 'tom',
1 => 'tom@tomshouse.com'
),
1 => array(
0 => 'james',
1 => 'james@jameshouse.com'
),
2 => array(
0 => 'marvin',
1 => 'marvin@marvinshouse.com'
),
3 => array(
0 => 'jane',
1 => 'jane@janeshouse.com'
),
);
$array2emails = array();
foreach ($array2 as $item) {
$array2emails[] = $item[1];
}
$result = array_diff($array2emails, $array1);
$results gives me
Array
(
[1] => james@jameshouse.com
[2] => marvin@marvinshouse.com
[3] => jane@janeshouse.com
)
however I need to get this:
Array
(
[1] => array(
[0] => james
[1] => james@jameshouse.com
)
[2] => array(
[0] => marvin
[1] => marvin@marvinshouse.com
)
[3] => array(
[0] => jane
[1] => jane@janeshouse.com
)
)
Any help would be much appreciated. Thanks