Skip to content

Instantly share code, notes, and snippets.

@zrkb
Last active April 11, 2019 14:44
Show Gist options
  • Select an option

  • Save zrkb/747866c47f47762989caf0fa7707160b to your computer and use it in GitHub Desktop.

Select an option

Save zrkb/747866c47f47762989caf0fa7707160b to your computer and use it in GitHub Desktop.

Revisions

  1. zrkb revised this gist Apr 11, 2019. No changes.
  2. zrkb revised this gist Apr 11, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ruc.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    <?php

    function digito_verificador($ci, $baseMax = 11)
    {
    $resultado = 0;
  3. zrkb created this gist Oct 12, 2018.
    13 changes: 13 additions & 0 deletions ruc.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    function digito_verificador($ci, $baseMax = 11)
    {
    $resultado = 0;
    $index = 0;
    for ($rucIndex = strlen($ci) - 1; $rucIndex >= 0; $rucIndex--) {
    $resultado += (int) $ci[$rucIndex] * ($index + 2);
    $r = $resultado % $baseMax;
    $index++;
    };
    $verificador = $r > 1 ? $baseMax - $r : 0;

    return $verificador;
    }