all php versions code example
Example 1: get the list of php versions installed
I use the following command to view installed PHP versions in Ubuntu:
========================================================================
sudo update-alternatives --list php
Example 2: latest php version
<?php
$json = file_get_contents('https://www.php.net/releases/?json');
$releases = [];
if ($json) $releases = json_decode($json, true);
$versions = array_keys($releases);
if (array_key_exists(max($versions), $releases)) {
echo $releases[max($versions)]['version'];
}