ramadani
ramadani

Reputation: 449

get an array that does not exist in another array

for example I have 2 arrays like the following:

array1 = (2, 3, 4);
array2 = (1, 2, 3, 4, 5);

I want to get the value of the second array, where the value array1 is not found in array2, so we can conclude the following are array3

array3 = (1, 5);

Upvotes: 0

Views: 1565

Answers (2)

Giacomo1968
Giacomo1968

Reputation: 26066

$array3 = array_diff($array1, $array2);

Upvotes: 1

Explosion Pills
Explosion Pills

Reputation: 191749

Diff the arrays

$array3 = array_diff($array2, $array1);

Upvotes: 5

Related Questions