/**
* check persons code
* @var cPcode string LV citizen person's code
* @return boolean
*/
function PCodeCheck($cPCode)
{
$cPCode = str_replace("-", "", $cPCode);
if (!preg_match("/^\d{11}$/", $cPCode))
return false;
$nCheckSum = 0;
$aCheck = array(1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
for ($i=0; $i<10; $i++ )
{
$nCheckSum += intval($cPCode[$i]) * $aCheck[$i];
}
return ((1101 - $nCheckSum) % 11)==substr($cPCode, -1);
}