I wanted to start developed my own payment system and i wanted to learn as much as i want on this so first i started with credit card validation algorithm mod 10
<?php
$array = $_POST['array']; //array holding numbers
$array = array_reverse($array); // reversing the array
echo "<br> Credit card Before :- ";
for($i=0;$i<sizeof($array);$i++)
echo $array[$i];
echo "<br>";
echo "<br> Credit card after applaying mod 10 Algorthim :- ";
//start converting the number
for($i=0;$i<sizeof($array);$i++){
if($i%2==1){
$array[$i] = $array[$i]+$array[$i];
if($array[$i]> 9 ){
$str = "$array[$i]";
$num = $str[0]+$str[1];
$array[$i] = $num;
}
}
//suming all the resulted number
$total +=$array[$i];
if($i%2==1)
echo "<b>".$array[$i]."</b>";
else
echo $array[$i];
}
echo "<br>";
if($total % 10 ==0){
echo "This creidet card is valid";
}else{
echo "This creidet card is not valid";
}
?>