RE: [PHP] Speaking of Global Annoyance
| From: | Jonathan Sharp | Date: | Mon, 18 Dec 2000 23:51:19 +0000 |
| Subject: | RE: [PHP] Speaking of Global Annoyance | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-30961@lists.php.net to get a copy of this message | ||
or you could:
function getimages(){
global $imagename;
...
}
and all you have to do is call the function... as getimages(); and
$imagename will be an array...thought this isn't the best way since you
start giving functions global scope...but it's kinda hard to return arrays
since you can't just do "return $thearray;" and then on the other end
"$anarray = somefunction();"
-sharpie!
-----Original Message-----
From: Jason Murray [mailto:Jason.Murray@melbourneit.com.au]
Sent: Monday, December 18, 2000 3:42 PM
To: 'Kevin Leavell'; php-general@lists.php.net
Subject: RE: [PHP] Speaking of Global Annoyance
1. I've taken the liberty of reformatting your code a little.
> 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
> }
> }
> }
2. At the end of this function, $imagename is local to the function. Try
this:
1. Add "return $imagename;" as the last line inside the { }'s.
2. When you call the function, make it:
$imagenamearray = getImages();
^^^^^^^^^^^^^^^ That'll be your array.
Jason
--
Jason Murray
jasonm@melbourneit.com.au
Web Design Team, Melbourne IT
Fetch the comfy chair!
--
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