Jump to content

[SOLVED] return() not returning...


Dragen

Recommended Posts

I'm having some trouble returning a value with a function.

It's my first look at using return and It looks fine to me.. it's for an image rotation script.

<?php
function imagerot(){
$dir = 'testimages/';
if(is_dir($dir)){
	if($opdir = opendir($dir)){
		while(($images = readdir($opdir)) !== false){
			if(filetype($dir . $images) == 'file'){
				$imagea[] = $dir . $images;
			}
		}
		closedir($opdir);
		$imagen = rand(0, count($imagea)-1);
		$size = getimagesize($imagea[$imagen]);
		$image = $imagea[$imagen] . '" ' . $size;
	}else{
		$image = $dir . 'default.gif';
	}
}else{
	$image = $dir . 'default.gif';
}
return $image;
}
?>
<img src="<?php imagerot() ?>" />

The problem is when I use return $image; it doesn't seem to return anything so I get an image where the filename is the name of the page.

If I use echo $image however it works fine, but I'm really wanting to get return to work. Any ideas?

Thanks

Link to comment
https://forums.phpfreaks.com/topic/54680-solved-return-not-returning/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.