Jump to content

Questions about Return in Function


doubledee

Recommended Posts

Some questions about the return statement in a Function...

 

1.) Do you have to assign what is being returned to a variable, before you can use the return statement.

 

For example, must you do this...

$postsPerDay = round(($numberOfPosts/$daysAsMember), 3);

return $postsPerDay;

 

 

Or is it acceptable to do this...

return round(($numberOfPosts/$daysAsMember), 3);

 

 

2.) Can you have return in multiple places in your Function?

 

For example, can you do this...

if ($estimatedAge < 20){
	return 'Youth';
}else if ($estimatedAge < 30){
	return '20-something';
}else if ($estimatedAge < 40){
	return '30-something';
}else{
	return 'Senior';
}

 

 

Or do you have to do this...

if ($estimatedAge < 20){
	$ageRange = 'Youth';
}else if ($estimatedAge < 30){
	$ageRange = '20-something';
}else if ($estimatedAge < 40){
	$ageRange = '30-something';
}else{
	$ageRange = 'Senior';
}

return $ageRange;

 

Thanks,

 

 

Debbie

 

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.