php - how can i pick out odd numbers from a series of numbers -


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

the above code generates series of numbers reversed ...the idea calculate luhn digit requires pick out odd numbers ...please how can achieve ??

$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


Comments