Machine-Readable Passport Check Digit
<p>In PHP, I'm trying to validate the second row (containing the date of birth) against a given date of birth. The different elements of the row, I have given different inputs, so there is no need to split the number up.</p>

<p>My question really is, for the date of birth, there is a check digit that validates the date of birth through a formula.</p>

<p>How can I validate the check digit with PHP?</p>

<p><a href="https://blogs.msdn.microsoft.com/alfredth/2007/12/20/a-simple-check-digit-project/" rel="nofollow" title="How the check digit works">How the check digit works</a><br>
<a href="https://en.wikipedia.org/wiki/Machine-readable_passport" rel="nofollow">Machine-readable passports - Wikipedia</a></p>

<p>[EDIT]</p>

<p>I've created some code that should work. For some reason, it always returns true.</p>

<pre><code>&lt;?php

//Set variables for passport number and the corresponding check digit
$passportnumber = "123456789";
$checkdigit= "7";

//Set variables for each character of the passport number    
$ppnumber1 = substr($passportnumber,0,1);   
$ppnumber2 = substr($passportnumber,1,1);    
$ppnumber3 = substr($passportnumber,2,1);    
$ppnumber4 = substr($passportnumber,3,1);    
$ppnumber5 = substr($passportnumber,4,1);    
$ppnumber6 = substr($passportnumber,5,1);    
$ppnumber7 = substr($passportnumber,6,1);    
$ppnumber8 = substr($passportnumber,7,1);    
$ppnumber9 = substr($passportnumber,8,1);    


//Check the passport number has been set properly
echo "Passport number is 
 $ppnumber1$ppnumber2$ppnumber3$ppnumber4$ppnumber5$ppnumber6$ppnumber7$ppnumber8$ppnumber9";  

$formula = ($ppnumber1*7) + ($ppnumber2*3) + ($ppnumber3*1) + ($ppnumber4*7) + ($ppnumber5*3) + ($ppnumber6*1) + ($ppnumber7*7) + ($ppnumber8*3) + ($ppnumber9*1);

$checker = $formula % 10;

if ($checker = $checkdigit){
echo "True";
} else{
echo "False";
}

?&gt;
</code></pre>