public static function personId($check)
{
$check = trim(str_replace('-', '', $check));
$pattern = '/^[0-9]{6}[0-9A-Z]{5}$/';
if (!(bool) preg_match($pattern, $check)) {
return false;
}
$date = \DateTime::createFromFormat('dmy', substr($check, 0, 6));
if ($date === false) {
return false;
}
$counter = 0;
$map = [0 => 1, 1 => 6, 2 => 3, 3 => 7, 4 => 9, 5 => 10, 6 => 5, 7 => 8, 8 => 4, 9 => 2];
foreach ($map as $index => $multiplier) {
$counter += (int) $check[$index] * $multiplier;
}
if ($counter === false) {
return false;
}
return (1101 - $counter) % 11 === (int) $check[10];
}