What are the potential pitfalls when merging arrays in PHP, especially when dealing with duplicate values?
When merging arrays in PHP, one potential pitfall is dealing with duplicate values. If not handled properly, merging arrays with duplicate values can result in overwriting existing values or losing data. To avoid this issue, you can use the array_merge() function combined with array_unique() to merge arrays while removing any duplicate values.
$array1 = [1, 2, 3];
$array2 = [3, 4, 5];
$mergedArray = array_unique(array_merge($array1, $array2));
print_r($mergedArray);