I am generating arrays of numbers.
$array1 = Array ( [0] => 50 [1] => 20 [2] => 13 [3] => 49 [4] => 67 )
I want to create and array from these arrays.
I want to check for duplicates.
if($array1 != $array2){
arraypush($array1, $array2);
}
You can use something like this:
$array1 = array([0] => 50 [1] => 20 [2] => 13 [3] => 49 [4] => 67 )
$array2 = array([0] => 50 [1] => 20 [2] => 13 [3] => 49 [4] => 67 )
foreach ($array1 as $key => $value) {
if ($array1[$key] != $array2[$key]) {
echo "the arrays are not equal";
// something you want to do
break;
}
}
For checking the duplicates, You would compare the array and use array_intersect([], [])
<!DOCTYPE html>
<html>
<body>
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"green","g"=>"blue");
$result=array_intersect($a1,$a2);
$result2=array_diff($a1,$a2);
print_r($result);
print_r($result2);
?>
</body>
</html>
The array_intersect() function compares the values of two (or more) arrays, and returns the matches.
The array_diff() function compares the values of two (or more) arrays, and returns the differences.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.