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
https://forums.phpfreaks.com/topic/263892-questions-about-return-in-function/
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.