Can you help me understand this simple PHP function, please?
<p>I would like to know how this function works so I can re-write it in ColdFusion. I've never programmed in PHP. <strong>I think</strong>, the function checks if $string is 11 numbers in length.</p>

<ol>
<li>But how is it doing it?</li>
<li>Why is it using a loop instead of a simple len() function?</li>
</ol>

<p>I read about str_pad(), and understand it. But what is the function of the loop iteration <code>$i</code> as a third argument? What's it doing?</p>

<pre><code>if($this-&gt;check_fake($cpf, 11)) return FALSE;

function check_fake($string, $length)
{
   for($i = 0; $i &lt;= 9; $i++) {
   $fake = str_pad("", $length, $i);
   if($string === $fake) return(1);
   }
}
</code></pre>

<p>The function is meant to validate a CPF, the Brazilian equivalent of a US SSN #. The CPF is 11 characters in length. Basically, I need to know what it's doing so I can write the function in Coldfusion.</p>

<p>If it's just a length, can't it be <code>if (len(cpf) != 11) return false;</code> ?</p>

<p>Here is the entire code snippet if it interests you:</p>

<pre><code>    &lt;?
    /*
    *@ Class VALIDATE - It validates Brazilian CPF/CNPJ numbers 
    *@ Developer: André Luis Cupini - andre@neobiz.com.br
    ************************************************************/
    class VALIDATE
    {
        /*
        *@ Remove ".", "-", "/" of the string
        *****************************************************/
        function cleaner($string)
        {
            return $string = str_replace("/", "", str_replace("-", "", str_replace(".", "", $string)));
        }

        /*
        *@ Check if the number is fake
        *****************************************************/
        function check_fake($string, $length)
        {
            for($i = 0; $i &lt;= 9; $i++) {
                $fake = str_pad("", $length, $i);
                if($string === $fake) return(1);
            }
        }

        /*
        *@ Validates CPF
        *****************************************************/
        function cpf($cpf) 
        {
            $cpf = $this-&gt;cleaner($cpf);
            $cpf = trim($cpf);
            if(empty($cpf) || strlen($cpf) != 11) return FALSE;
            else {
                if($this-&gt;check_fake($cpf, 11)) return FALSE;
                else {
                    $sub_cpf = substr($cpf, 0, 9);
                    for($i =0; $i &lt;=9; $i++) {
                        $dv += ($sub_cpf[$i] * (10-$i));
                    }
                    if ($dv == 0) return FALSE; 
                    $dv = 11 - ($dv % 11); 
                    if($dv &gt; 9) $dv = 0;
                    if($cpf[9] != $dv) return FALSE;

                    $dv *= 2;
                    for($i = 0; $i &lt;=9; $i++) {
                        $dv += ($sub_cpf[$i] * (11-$i));
                    }
                    $dv = 11 - ($dv % 11); 
                    if($dv &gt; 9) $dv = 0;
                    if($cpf[10] != $dv) return FALSE;
                    return TRUE;
                }
            }
        }
}
?&gt;
</code></pre>
