Home >Backend Development >PHP Tutorial >How to Merge Two Arrays and Eliminate Duplicate Email Values in PHP?
Merging Arrays and Eliminating Duplicate Email Values
Merging arrays and removing duplicate values is a common task when dealing with data. In this case, we are given two arrays of objects containing email addresses. The objective is to merge these arrays while eliminating any duplicated email values.
To achieve this, we employ a two-step approach:
Merging the Arrays:
Eliminating Duplicates:
By combining these two functions, we can achieve our goal of merging the arrays and removing duplicate email values. The following PHP code demonstrates this process:
$array1 = [ (object) ["email" => "gffggfg"], (object) ["email" => "example@example.com"], (object) ["email" => "wefewf"], ]; $array2 = [ (object) ["email" => "example@example.com"], (object) ["email" => "wefwef"], (object) ["email" => "wefewf"], ]; $mergedArray = array_unique(array_merge($array1, $array2)); print_r($mergedArray);
The output of the above code will be an array containing the unique objects from both input arrays, with duplicate email values removed.
The above is the detailed content of How to Merge Two Arrays and Eliminate Duplicate Email Values in PHP?. For more information, please follow other related articles on the PHP Chinese website!