How can PHP functions like array_filter and array_intersect be utilized to search for specific values in an array?

To search for specific values in an array using PHP functions like array_filter and array_intersect, you can use array_filter to filter the array based on a callback function that checks for the specific value, and array_intersect to find the common values between two arrays.

// Example array to search
$array = [1, 2, 3, 4, 5];

// Using array_filter to search for specific value
$searchValue = 3;
$searchedArray = array_filter($array, function($value) use ($searchValue) {
    return $value == $searchValue;
});

// Using array_intersect to find common values between two arrays
$compareArray = [2, 3, 4];
$commonValues = array_intersect($array, $compareArray);

print_r($searchedArray);
print_r($commonValues);