How can one optimize the process of checking multiple strings against a list in PHP for better performance?

When checking multiple strings against a list in PHP for better performance, it is recommended to use an associative array where the strings are keys for fast lookups. This allows for constant time complexity O(1) lookups compared to linear time complexity O(n) when using in_array() function.

// Create an associative array where the strings are keys
$list = [
    'string1' => true,
    'string2' => true,
    'string3' => true,
    // Add more strings as needed
];

// Check if a string exists in the list
$stringToCheck = 'string1';
if (isset($list[$stringToCheck])) {
    echo "String exists in the list";
} else {
    echo "String does not exist in the list";
}