I have two arrays :
JavaScript
x
$array1 = [460,471];
$array2 = [193,42,471];
I want to take the value only in $array1
if there is no same value in $array2
, if there is a same value in $array2
filter it out.
Expected output if no same value available in $array2
:
JavaScript
$output = [460, 471]
Expected output is there is same value in $array2
:
JavaScript
$output = [460]
Advertisement
Answer
Try array_diff()
function
JavaScript
$array1 = [460,471];
$array2 = [193,42,471];
$filtered = array_diff($array1,$array2);
print_r($filtered);