BecauseGeek BecauseGeek - 3 years ago 202
PHP Question

How do I filter the records of one array by those that do not exist in another array?

I have two result sets:

$array1 = (0=>'name1',1=>'name2');


and

$array2 = (0=>'name',1=>'name1',2=>'name2',3=>'name4');


I want to loop through array2 and eliminate any record that does exist in array1

For some reason I can't use this syntax:

select * where not in(select ....)

Answer Source

For a SQL select which has multiple fields for the key, you can use the following syntax...

SELECT *
FROM CompletedTasks
WHERE (userID, taskID) NOT IN
      ( SELECT userID, taskID
        FROM PlannedTasks
      ) ;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download