note 73823 deleted from function.mt-rand by cmb
| From: | cmb@php.net | Date: | Sun, 31 Mar 2019 08:34:53 +0000 |
| Subject: | note 73823 deleted from function.mt-rand by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210459@lists.php.net to get a copy of this message | ||
Note Submitter:
----
In one of my forums was a discussion about, how to change an image randomly, so i wrote this code
using mt_rand ....
I hope you can use it ....
I Forgot something, sorry for that, but here is the correction.
<?php
//ImageChange.php
error_reporting(0);//hide the notice for the missing $iRand
$sPath2ImageDir = Path;//preventing redundancy
$aImages = scandir($sBildOrdnerPfad);//Dir 2 Array
$iImageCount = count($aImages);//preventing redundancy
while (getimagesize("{sPath2ImageDir}/{$aImages[$iRand]}")) {//recursion to get an image
$iRand = mt_rand(2, $iImageCount-1);//min = 2 because $aImages[0] = "." and $aImages[1]
= ".."
}
echo "<img alt=\"Image{$iRand}\"
src=\"{sPath2ImageDir}/{$aImages[$iRand]}\" title=\"Image{$iRand}\"
/>";//show the image
unset($aImages, $iImageCount, $iRand, $sBildOrdnerPfad);//if this script is used in another script
?>