davidlee
davidlee

Reputation: 6167

Remove values in a flat indexed array if found in another flat array

I would like to filter an array.

$a = ['a', 'b', 'c', 'd', 'e'];
$b = ['c', 'd'];

$a will be filtered by values in array $b and the result should be:

['a', 'b', 'e']

Upvotes: 0

Views: 1015

Answers (2)

Gabriel Poama-Neagra
Gabriel Poama-Neagra

Reputation: 481

Try array_diff();

PHP Documentation: http://php.net/manual/en/function.array-diff.php

Upvotes: 9

zerkms
zerkms

Reputation: 254896

$result = array_diff($a, $b)

Upvotes: 3

Related Questions