PHP provides different versions with different features. The latest PHP version is 7.4 as writing this post. Different versions of the PHP deployed in different platforms. The phpversion() function can be used to print currently running PHP version.
phpversion() Function Syntax
The phpversion() function syntax is like below. The EXTENSION parameter is optional and if not provided the currently running PHP version is printed. The phpversion() function returns the version information as string.
phpversion(EXTENSION)
- EXTENSION is an optional parameter If not specified it prints the current PHP version. The EXTENSION is used to specify the extension name as string in order to display specific extension version.
Print Currently Running PHP Version
The currently running PHP version can be returned as string with the phpversion() function.
<?php
phpversion = phpversion();
?>
Alternatively, the PHP version can be directly displayed or printed with the echo command like below.
<?php
echo phpversion();
?>
Print Specific Extension Version
The phpversion() function can be also used to print the extension version. Just provide the extension name as string to the phpversion() function.
<?php
$extension_version=phpversion("mysqli");
echo $extension_version;
?>