daniel-plewinski
8/18/2017 - 9:17 PM

Verify PESEL

Verify PESEL

<?php
function verifyPesel($pesel) {
    $arrPes = str_split($pesel);
    $arrPes[0] = $arrPes[0] * 1;
    $arrPes[1] = $arrPes[1] * 3;
    $arrPes[2] = $arrPes[2] * 7;
    $arrPes[3] = $arrPes[3] * 9;
    $arrPes[4] = $arrPes[4] * 1;
    $arrPes[5] = $arrPes[5] * 3;
    $arrPes[6] = $arrPes[6] * 7;
    $arrPes[7] = $arrPes[7] * 9;
    $arrPes[8] = $arrPes[8] * 1;
    $arrPes[9] = $arrPes[9] * 3;
    $controlNum = array_pop($arrPes);
    echo "<br>";
    $controlNum = (int) $controlNum;
    $total = array_sum($arrPes);
    $modulo = $total % 10;
    $subtracted = 10 - $modulo;
    if ($modulo === 0 || $subtracted === $controlNum) {
        return true;
    } else {
        return false;
    }
}
var_dump(verifyPesel(75021011611));
echo "<br>";
var_dump(verifyPesel(49040501580));
echo "<br>";
var_dump(verifyPesel(81021590999));