SHARE
TWEET

Untitled

a guest Oct 15th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $codigo="65839522";
  3. $control=substr($codigo,strlen($codigo)-1,1);
  4. $cod=substr($codigo,0,strlen($codigo)-1);
  5. $total=0;
  6. $actual=0;
  7. //Le damos la vuelta al codigo
  8. $cod=strrev($cod);
  9. for ($i=0;$i<strlen($cod);$i++){
  10.     //$actual=($i%2==0) ?substr($cod,$i,1) *3:substr($cod,$i,1);
  11.     if ($i%2==0) {
  12.         $actual=substr($cod,$i,1) *3;
  13.     }
  14.     else {
  15.         $actual=substr($cod,$i,1);
  16.     }
  17.     $total=$total+$actual;
  18. }
  19. echo $total;
  20. $faltan=10-$total%10;
  21.  
  22. if ($faltan==$control) {
  23.     echo "Correcto"
  24. }
  25. else {
  26.     echo "Incorrecto";
  27. }
  28. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top