What are the best practices for optimizing PHP code when checking for the existence of a value in an array?

When checking for the existence of a value in an array in PHP, it is best practice to use the in_array() function instead of iterating over the array manually. This function provides a more concise and efficient way to check if a value exists in an array.

// Example of using in_array() function to check for the existence of a value in an array
$fruits = array("apple", "banana", "orange", "grape");

if (in_array("banana", $fruits)) {
    echo "Banana is in the array";
} else {
    echo "Banana is not in the array";
}