Hello People, I just started PHP a few days ago so please bear with me. I'm trying to write a credit card validation function recursivly. It works with small number of digits (lets say 4) but when i add more digits (15), the whole thing just screws up. Any ideas?
function sumLuhn($number, $i, $cardlength)
{
$odd = sumOdd($number , $i, $cardlength);
$even = sumEven($number, $i+1, $cardlength); $outLuhn = $even + $odd; return $outLuhn; } function sumOdd($number, $i, $cardlength) { if ($i<=$cardlength) { $digit =substr($number, $i*-1,1); $outOdd = $digit; $outOdd = $outOdd + "sumOdd($number, $i + 2, $cardlength)"; } return $outOdd; } function sumEven($number, $i, $cardlength) { if ($i<=$cardlength) { $digit = substr($number, $i*-1,1); if (2*$digit>10 or 2*$digit=10) { $digit = $digit * 2; $digit1 = substr($digit,-1,1); $digit = $digit1 + substr($digit,-2,1); $digit = $digit/2; } $outEven = 2*$digit; $outEven = $outEven + "sumEven($number, $i + 2, $cardlength"; } return $outEven; }