Using same fuction 2nd time

SIDNEY MORRIS

New Member
I'm declaring the following function to get a random image from a directory. I want to use the same function in same code to get random image from a different directory. Now the problem is that I have to change $path but I have already used it in declaration while i want to use the different path when I use the function 2nd timeDeclaration part\[code\]function getImagesFromDir($path) { $images = array(); if ( $img_dir = @opendir($path) ) { while ( false !== ($img_file = readdir($img_dir)) ) { // checks for gif, jpg, png if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) { $images[] = $img_file; } } closedir($img_dir); } return $images; } \[/code\]I use it this way 1st time\[code\]$root = ''; $path = 'frames/';$imgList = getImagesFromDir($root . $path); $img = getRandomFromArray($imgList); \[/code\]How shud i use it 2nd time so that it chooses image from different directory.
 
Back
Top