解析JSON文件并比较semvers

I have a json file that looks roughly something like this.

{
   "foo" : {
      "name" : "bar", 
      "dev-master" : {}, 
      "3.0-dev" : {}, 
      "2.4" : {}, 
      "master" : {},
   }
}

I would like to know if there is a solution to parse and get the most resent semver tag. I tried as far as:

<?php 
$file = 'data.json'; 
$content = file_get_contents($file); 
$content = json_decode($content); 

$container = [];
foreach($content as $version){
  $container[$version] = $version; 
}

.. 

Now, assuming that $container contains all the tags, how do I get the most recent version would would be 2.4.

Getting the 2.4 is not the problem, but making a future-proof reliable way to find out which is the recent.

This is one approach. It uses the assumption that the most recent version number would be composed of only digits and decimal points. You can update the regular expression to allow dashes, etc.

#!/usr/bin/php
<?php
$content = json_decode(file_get_contents('data.json'));
$container = [];
foreach($content as $name => $versions){
        $props   = get_object_vars($versions);
        $container[$name] = null;
        foreach (array_keys($props) as $versionName) {
                if (preg_match('/^[0-9\.]+$/',$versionName)) {
                        // Ensure if multiple versions are present the greatest 
value will be used
                        if (isset($container[$name])) {
                            $container[$name] = max($versionName,$container[$nam
e]);
                        } else {
                            $container[$name] = $versionName;
                        }
                }
        }
}
var_dump($container);

If no final version is found, the version name will be null.