Got an problem while doing my task.
I have two arrays, first array show random numbers from 20 to 60. Second array show numbers from 40 to 80.
I need to create a third array which is going to be a merge of two arrays but without duplicates.
My code looks like this:
$myLength=mt_rand(50,80);
$array1=array();
for ($i=0;$i<$myLength;$i++){
$array1[$i]=mt_rand(20,60);
}
print_r($array1);
echo "<br>";
$array2=array();
for ($i=0;$i<$myLength;$i++){
$array2[$i]=mt_rand(40,80);
}
print_r($array2);
echo "<br>";
$array3 = array_merge($array1,$array2);
if ($array2!=$array1) {
print_r($array3);
}
I probably understand that I can fix that with something like
if(arr1.value != arr2.value) { print value to arr3 }
But I don't know how to implement it. Or maybe there is even easier option to do it, but I stuck and just trying to find a way of doing it. Maybe there is already ready function for this task?
Any ideas how I can make it most precise way?