What is the purpose of using in_array() function in PHP and what are the potential pitfalls when using it?

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, and false otherwise. When using in_array(), potential pitfalls include not specifying the third parameter as true for strict type checking, which can lead to unexpected results when comparing values of different types.

// Using in_array() with strict type checking
$fruits = ['apple', 'banana', 'orange'];
if (in_array('apple', $fruits, true)) {
    echo 'Apple is in the array';
} else {
    echo 'Apple is not in the array';
}