How can PHP be used to specifically query for either IPv4 or IPv6 addresses to avoid switching between them?

To specifically query for either IPv4 or IPv6 addresses in PHP, you can use the `filter_var` function with the `FILTER_VALIDATE_IP` filter option along with the `FILTER_FLAG_IPV4` or `FILTER_FLAG_IPV6` flag. This will allow you to validate and differentiate between IPv4 and IPv6 addresses without needing to switch between them manually.

// Check for IPv4 address
$ipAddress = "192.168.1.1";
if (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
    echo "IPv4 address detected: " . $ipAddress;
}

// Check for IPv6 address
$ipAddress = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
if (filter_var($ipAddress, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
    echo "IPv6 address detected: " . $ipAddress;
}