Created
March 3, 2018 16:01
-
-
Save panakuma/02b5db9d298e2acb77e89e4bc2e5b37c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function IsbnConsistencyCheck($isbn){ | |
$isbn_arr = str_split($isbn); | |
$odd = 0; | |
$mod = 0; | |
for($i=0;$i<(count($isbn_arr)-1);$i++){ | |
if($i % 2 == 0) $mod += (int)$isbn_arr[$i]; | |
else $odd += (int)$isbn_arr[$i]; | |
} | |
$odd *= 3; | |
$check_digit = 10 - (($mod + $odd) % 10); | |
if(substr($isbn, -1) == $check_digit) return true; | |
else return false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment