3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function compareVersion($version1, $version2) { $partsV1 = explode('.', $version1); $partsV2 = explode('.', $version2); $partsV1Size = count($partsV1); $partsV2Size = count($partsV2); $longest = max($partsV1Size, $partsV2Size); for ($i = 0; $i < $longest; ++$i) { $v1 = $partsV1Size > $i ? intval($partsV1[$i]) : 0; $v2 = $partsV2Size > $i ? intval($partsV2[$i]) : 0; if ($v1 < $v2) { return -1; } else if ($v1 > $v2) { return 1; } } return 0; } var_dump(compareVersion("01.0", "1"));
based on E5NqI
Output for 4.3.0 - 7.2.0
int(0)