-1
<?php
$i=1;
while($i<=13)
{
   $rev=rand(0,9);
   $Rev=strrev($rev);
   echo $Rev;
   $i++;
}
?>

The above code generates a series of numbers which are reversed ...the idea is to calculate the luhn digit which requires that you pick out odd numbers ...please how can I achieve this ??

GrandMasterFlush
  • 6,269
  • 19
  • 81
  • 104

1 Answers1

0
$i=1;

while($i<=13){

    $rev=rand(0,9);
    $rev=strrev($rev);

    if ($rev % 2 != 0) {
        echo $rev;
    }

$i++;


}

UPDATE:

$i = 0;
while($i<=13){

    $rev=rand(0,9);
    $rev=strrev($rev);

    $all_numbers[] = $rev;

    if ($rev % 2 != 0) {
        $odd_numbers[] = $rev;
    }

$i++;


}

echo "<h2>All numbers</h2><pre>";
print_r($all_numbers);
echo "</pre>";

echo "<h2>Odd numbers</h2><pre>";
print_r($odd_numbers);
echo "</pre>";

Output:

enter image description here

Emil
  • 1,786
  • 1
  • 17
  • 22
  • the code you wrote no longer generates the usual 14 digits..please I mean after it generates the 14 digits the next thing is to pick out the odds from it...not directly generate odds – Iorzua Emmanuel Jul 16 '15 at 10:21
  • You're welcome! Please mark the answer as correct if it helped you to solve your problem :) – Emil Jul 16 '15 at 11:22