How can one ensure compatibility between PHP versions when transferring projects from local to web hosting?

When transferring projects from local to web hosting, it is important to ensure compatibility between PHP versions to avoid any unexpected errors or issues. One way to ensure compatibility is to check the PHP version on both your local environment and the web hosting server and make any necessary updates or adjustments to your code to accommodate any differences.

// Check PHP version
if (version_compare(PHP_VERSION, '7.0.0') < 0) {
    // Handle compatibility issues for PHP versions below 7.0.0
} else {
    // Code that is compatible with PHP 7.0.0 and above
}