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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.