How can a PHP function be written to determine if a string is a "Query"?

To determine if a string is a "Query," we can check if the string starts with a question mark '?' followed by key-value pairs separated by '&'. We can achieve this by using regular expressions in PHP to match the pattern of a query string.

function isQueryString($string) {
    return preg_match('/^\?.+=.+(?:&.+=.+)*$/', $string);
}

// Example usage
$string1 = "?key1=value1&key2=value2";
$string2 = "key1=value1&key2=value2";
var_dump(isQueryString($string1)); // Output: int(1)
var_dump(isQueryString($string2)); // Output: int(0)