What are some best practices for writing custom functions in PHP for specific tasks like checking string inclusion in arrays?

When writing custom functions in PHP to check for string inclusion in arrays, it is important to create a reusable function that takes in the array and the string to check as parameters. This function should iterate through the array and compare each element to the target string using a case-insensitive comparison to ensure accurate results. Additionally, the function should return a boolean value indicating whether the string is present in the array or not.

function checkStringInArray($array, $target){
    foreach($array as $element){
        if(strcasecmp($element, $target) === 0){
            return true;
        }
    }
    return false;
}

// Example usage
$array = ["apple", "banana", "orange"];
$target = "Banana";
if(checkStringInArray($array, $target)){
    echo "String found in array";
} else {
    echo "String not found in array";
}