DEV Community

Programming Dive
Programming Dive

Posted on

Return statement in PHP

The return statement is an important language constraint to return the value to the caller. In this tutorial, we’ll see different uses of return statements in PHP with examples.

I know that there is nothing special in creating this post only for return statement. But believe me, this will create new opportunities of using return statement in different part of the codebase and we’ll understand how dynamically we can use it in our day to day coding.

In most of the scenarios, we have seen this return statement inside the function definition only.

https://programmingdive.com/different-uses-of-return-statement-in-php/

Top comments (13)

Collapse
 
moopet profile image
Ben Sinclair

Hi, I notice your posts are generally teasers with links to off-site content. If you include the whole post here, people here will have a better DEV experience - and you can set the canonical url in each post to reference your site, so you don't end up with SEO woes.

Collapse
 
programmingdive profile image
Programming Dive

Hi Ben , thanks for the suggestion
I am actually afraid whether google will penalize my website because duplicate content. If this does not happen then I love to share my whole work here and as you said I will give canonical url to my webpage

Collapse
 
marcusatlocalhost profile image
Marcus

Stand up to your fears, there is nothing to be afraid of ;-) and according to this article[1], "duplicate content penalty" doesn't exist. You try to game google, which could end up to be more harmful.

[1] hobo-web.co.uk/duplicate-content-p...

Thread Thread
 
programmingdive profile image
Programming Dive

Thanks for the clarification Marcus.. here is the question.i posted my blog first and then provided that content here but still I can see this post ranked above my webpage.. I really don't understand this

Thread Thread
 
jsn1nj4 profile image
Elliot Derhay • Edited

DEV itself probably has a higher score because of how active it is and all of the Backlinks (including a lot of activity and links on a big social network like Twitter).

Thread Thread
 
mxldevs profile image
MxL Devs

dev.to likely is considered to be more relevant due to its scale. But that shouldn't be seen as a bad thing they're still going to see your article. I would focus on how to brand your posts instead.

Thread Thread
 
stephanie profile image
Stephanie Handsteiner

Yes, because dev.to in general is considered more relevant than your personal blog.

That's what canonical url's are for, to let google know that the original of this content lives on another site (your blog in this case), so you're doing actually more harm to you not using the canonical url feature than if you'd use it.

Thread Thread
 
programmingdive profile image
Programming Dive

Got it.. can you guys give me any example from dev.to where original post is on authors personal website but it's canonical url is pasted here along with post
Thanks

Thread Thread
 
mxldevs profile image
MxL Devs

My understanding is you would set up your own site with canon meta tag moz.com/learn/seo/canonicalization

Thread Thread
 
moopet profile image
Ben Sinclair

If you add this to your post's front matter here:

canonical_url: https://programmingdive.com/different-uses-of-return-statement-in-php/

Then search engines should know that the "real" blog post lives on your own site.

Thread Thread
 
programmingdive profile image
Programming Dive • Edited

That's cool but the question is when I post my blog here with same title and content then dev.to also creates canonical tag with same title. Then how google will distinguish which is the original content?

Thread Thread
 
moopet profile image
Ben Sinclair

I'm not sure I understand what you mean?

Thread Thread
 
marcusatlocalhost profile image
Marcus • Edited

@programmingdive Google knows the post on your blog is the original one, because you set the canonical_url here on dev.to (I didn't know that's possible, but good to know)

As I see it, you try to game google[1] and you use dev.to to get some ranking for your blog. That's fine! dev.to encourages this and even gives you the tools (no rel="nofollow" and canonical_url tag). But for dev.to users, teaser posts like this can be seen as low quality (ok, I'm just speaking just for myself here) and I don't think that helps the overall quality of site (also, just my opinion).

I'd say, check out all options, and how google ranks your site under different circumstances and then write an exclusive dev.to post about what you have learned :).

[1] and google doesn't like that, tries to detect that behavior.