by Hiroshi on June 19th, 2008

for loop

I am describing for loop with an example that include randomizing number display using images from a directory. Use following script and create a folder nb and put images 0.gif, 1.gif, … , 9.gif containing same digit over each and see.

PHP Code

<?php
$mynumber= rand(1111111111,9999999999);
// echo $mynumber;
$ilength=strlen($mynumber);
for($i=0; $i<$ilength; $i++)
{
$ipic= substr($mynumber, $i, 1);
$sFilePath = "";
if (file_exists("nb/".$ipic.".gif"))
$sFilePath = "nb/".$ipic.".gif";
?>
<img src="<?= $sFilePath ?>">
<?php
}
?>

For Loop Rand Numbers Script Download

  • Share/Bookmark

Leave a Review