How can the PHP functions array_diff and array_intersect be used to compare two arrays with numerical values?
To compare two arrays with numerical values in PHP, you can use the functions array_diff and array_intersect. - array_diff function returns an array containing all the values from array1 that are not present in any of the other arrays. - array_intersect function returns an array containing all the values that are present in all of the arrays. Here is an example code snippet that demonstrates how to use these functions to compare two arrays with numerical values:
$array1 = [1, 2, 3, 4, 5];
$array2 = [3, 4, 5, 6, 7];
$diff = array_diff($array1, $array2);
$intersect = array_intersect($array1, $array2);
echo "Values in array1 that are not in array2: ";
print_r($diff);
echo "Values common to both arrays: ";
print_r($intersect);