PHP Magic Book – Free PHP Scripts, Tutorials and Downloads, PHP AtoZ Reloaded, free php tutorials, free php downloads, php scripts, PHP tips

For Loop in PHP

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
Tags:
Posted in: Loops, Randomizing, Scripts
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0

Related Posts




Post a Comment

  Subscribe Via RSS
  Subscribe Via Email