Zend - The PHP Company




Commerce

Add Code


highly efficient Mod 10 function for credit card validation  

Type: code fragment
Added by: jlopez123
Entered: 23/07/2003
Last modified: 07/12/2002
Rating: - (fewer than 3 votes)
Views: 6184
this is a very simple function that performs a mod 10 on a credit card number. this function is not meant to be a complete solution, I only wanted to show how the mod 10 portion of a credit card validation function could be done quickly and efficiently.


<?php
function mod10cc$ccnum ) {
    
$double = array( 0,2,4,6,8,1,3,5,7,);
    
$ccnum strrev$ccnum );
    for( 
$i=0$i<strlen$ccnum ); $i++ )
        
$values[] = ( $i&) ? $double[$ccnum[$i]] : $ccnum[$i];
    return ( 
array_sum$values ) % 10 ) ? 1;
}
?>


Usage Example




Rate This Script





Search



This Category All Categories