What role does the PHP version play in ensuring the compatibility of a script across different servers?

The PHP version plays a crucial role in ensuring compatibility of a script across different servers because certain functions and features may be deprecated or changed in newer versions of PHP. To ensure compatibility, it's important to develop and test scripts using the lowest common PHP version among the servers where the script will be deployed.

// Specify the minimum required PHP version in your script
if (version_compare(PHP_VERSION, '7.0.0') < 0) {
    die('This script requires at least PHP 7.0.0 to run. Please upgrade your PHP version.');
}

// Your script code goes here