Q:

Write a PHP script to compare the PHP version

0

Write a PHP script to compare the PHP version.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
if (version_compare(PHP_VERSION, '6.0.0') >= 0) {
echo 'I am at least PHP version 6.0.0, my version: ' . PHP_VERSION . "\n";
}
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
echo 'I am at least PHP version 5.3.0, my version: ' . PHP_VERSION . "\n";
}

if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
echo 'I am using PHP 5, my version: ' . PHP_VERSION . "\n";
}

if (version_compare(PHP_VERSION, '5.0.0', '<')) {
echo 'I am using PHP 4, my version: ' . PHP_VERSION . "\n";
}
?>

Sample Output:

I am at least PHP version 6.0.0, my version: 7.0.15-0ubuntu0.16.04.4
I am at least PHP version 5.3.0, my version: 7.0.15-0ubuntu0.16.04.4
I am using PHP 5, my version: 7.0.15-0ubuntu0.16.04.4 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now