What is the purpose of the in_array() function in PHP and how is it typically used?

The in_array() function in PHP is used to check if a value exists in an array. It returns true if the value is found in the array, and false otherwise. This function is commonly used to perform conditional checks based on the presence of a specific value in an array.

// Example usage of in_array() function
$fruits = array("apple", "banana", "orange", "grape");
$fruit_to_check = "banana";

if (in_array($fruit_to_check, $fruits)) {
    echo "The fruit is in the array.";
} else {
    echo "The fruit is not in the array.";
}