Credit card validation with reversed array I want a review of this code.

&lt;?php
  $array = $_POST['array'];  //array holding numbers
  $array = array_reverse($array);          // reversing the array
  echo "&lt;br&gt; Credit card Before :- ";
  for($i=0;$i&lt;sizeof($array);$i++)
    echo $array[$i];
  echo "&lt;br&gt;";
  echo "&lt;br&gt; Credit card after applaying mod 10 Algorthim :- ";
  //start converting the number
  for($i=0;$i&lt;sizeof($array);$i++){
    if($i%2==1){
      $array[$i] += $array[$i];
        if($array[$i]&gt; 9 ){

          $array[$i] -= 9;
        }
      }
      //suming all the resulted number
      $total +=$array[$i];
      if($i%2==1)
        echo "&lt;b&gt;".$array[$i]."&lt;/b&gt;";
      else
        echo $array[$i];
    }
    echo "&lt;br&gt;";
      if($total % 10 ==0){
        echo "This creidet card is valid";
      }else{
        echo "This creidet card is not valid";
      }
?&gt;
There's a few glaring issues with your code. Namely your lack of consistent styling. Secondly, you're not doing certain things correctly (iterating over an array rather than imploding it). As this is a code review, I will not be touching on the correctness of the algorithm. Below you'll find two pieces of code - one which I've commented and corrected, and a second which I've removed my comments and old code. 

With comments:

&lt;?php

# Grab the numbers array and reverse it. 
# Don't just name your variable $array. Name it something meaningful.
$numbers_array = array_reverse( $_POST['array'] );

echo "&lt;br&gt; Credit card Before :- ";

# No need to do a for loop, just use implode to make the array into a string
/*for ( $i = 0; $i &lt; sizeof( $array ); $i++ ){
    echo $array[$i];
}*/
echo implode("", $numbers_array);

# Just do one echo instead of two
/*echo "&lt;br&gt;";*/
echo "&lt;br&gt;&lt;br&gt; Credit card after applaying mod 10 Algorthim :- ";

# Start converting the number
# You're doing a sizeof() on every single loop. Just cache it in a $size variable
$size = count($numbers_array);
for ( $i = 0; $i &lt; $size; $i++ ) {
    if ( $i % 2 == 1 ) {
        $numbers_array[$i] += $numbers_array[$i];
        if ( $numbers_array[$i] &gt; 9 ) {
            $numbers_array[$i] -= 9;
        }

        echo "&lt;b&gt;" . $numbers_array[$i] . "&lt;/b&gt;";
    } else {
        echo $numbers_array[$i]
    }

    $total += $numbers_array[$i];

    # You're doing the same calculation twice (as above). Why not just echo it up there?
    /*if ( $i % 2 == 1 ){
        echo "&lt;b&gt;" . $numbers_array[$i] . "&lt;/b&gt;";
    } else {
        echo $numbers_array[$i];
    }*/
}

echo "&lt;br&gt;";
if ( $total % 10 == 0 ) {
    echo "This credit card is valid";
} else {
    echo "This credit card is not valid";
}


With no comments:

&lt;?php

# Grab the numbers array and reverse it. 
$numbers_array = array_reverse( $_POST['array'] );

echo "&lt;br&gt; Credit card Before :- " . implode("", $numbers_array) . 
     "&lt;br&gt;&lt;br&gt; Credit card after applaying mod 10 Algorthim :- ";

# Start converting the number
$size = count($numbers_array);
for ( $i = 0; $i &lt; $size; $i++ ) {
    if ( $i % 2 == 1 ) {
        $numbers_array[$i] += $numbers_array[$i];
        if ( $numbers_array[$i] &gt; 9 ) {
            $numbers_array[$i] -= 9;
        }

        echo "&lt;b&gt;" . $numbers_array[$i] . "&lt;/b&gt;";
    } else {
        echo $numbers_array[$i]
    }

    $total += $numbers_array[$i];
}

if ( $total % 10 == 0 ) {
    echo "&lt;br&gt;This credit card is valid";
} else {
    echo "&lt;br&gt;This credit card is not valid";
}