convert php verstion to int

    0

    0

    jvit
    JVIT PHP

    This function will convert the PHP version from a string to an integer.

    This function will convert the PHP version from a string to an int.

    Shortcut: system.convertVersion

    /**
    * convert PHP version from string to int
    */
    function convertPHPVersionToInt(string $version): int
    {
      $explodeDash = \explode('-', $version);
      if (\count($explodeDash) > 1) {
        $version = $explodeDash[0];
      }
      $explodeVersion = \explode('.', $version);
      $countExplodedVersion = \count($explodeVersion);
      if ($countExplodedVersion === 2) {
        return (int) $explodeVersion[0] * 10000 + (int) $explodeVersion[1] * 100;
      }
      if ($countExplodedVersion >= 3) {
        return (int) $explodeVersion[0] * 10000 + (int) $explodeVersion[1] * 100 + (int) $explodeVersion[2];
      }
      return (int) $version;
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.