This page all about compares two arrays and remove the duplicates from the main array in PHP. Here I will explain How can we do that, we have a predefined function in PHP array_diff($main_array, $subarray), Now we can get the result.
1 2 3 4 5 6 | <?php $arr_1 = array(1,2,3,4); $arr_2 =array(3,4); $arr_3 = array_diff($arr_1,$arr_2); print_r($arr_3); ?> |
Output:
1 | Array ( [0] => 1 [1] => 2 ) |