RE: [PHP] Speaking of Global Annoyance
| From: | Dave VanAuken | Date: | Tue, 19 Dec 2000 00:01:48 +0000 |
| Subject: | RE: [PHP] Speaking of Global Annoyance | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-30969@lists.php.net to get a copy of this message | ||
first thing that comes to mind is returning the value (didn't check much
else since you said the code was functional outside of the function)
excuse my reformatting, I find it easier to assess this way
function getimages(){
chdir("images");
$dir = dir(".");
$dir->rewind();
while ($file=$dir->read()){
if(!is_dir("$file")){
$imagename[$file] = $file;
}
}
return $imagename; #actually spits something back out
}
#call the function to get the imagename array
#assign it to variable (now array)
$imagename=getimages();
-----Original Message-----
From: Kevin Leavell [mailto:k@bigsky.net]
Sent: Monday, December 18, 2000 6:39 PM
To: php-general@lists.php.net
Subject: [PHP] Speaking of Global Annoyance
I want to return the array of image names ($imagename) from a directory so
the script doesn't have to read the directory constantly. I have tried
global and return and $GLOBAL but $imagename comes back empty.
It works just fine until I try to implement the function.
function getimages()
{
chdir("images"); //read image names from directory /images
$dir = dir(".");
$dir->rewind();
while ($file=$dir->read())
{
if(!is_dir("$file")) //if the variable isn't a directory then put it in the
array imagename
{
$imagename[$file] = $file; //adds the filename to the array imagename
}
}
}
Image viewing code here
Thanks
Kevin Leavell
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net