What is the purpose/point of echo, endif, and return? Also, whilst on this subject, why should I enclose values in " " when enclosing them in ' ' works just as well?

I know echo can be used in place of print, but why and when should I use echo over print?

endif is mentionned in passing all over the place in PHP documentation, along with something called MVC (Model-View-Controller software engineering), but does it have any purpose/use in everyday PHP website design?

return is something else that I tried to use, but the only thing it ever does is crash our website. - Is this similar to die() (which I have used successfully), or what?

- I have looked up the documentation on these and cannot find a proper answer on their use and/or how to properly implement them; hence my asking for help on clarifying these - I really do not want to be just another 'programmer' in my PHP as opposed to being an actual programmer, so knowing the answer to things like this is important to me.

echo vs print
Time to find on the internet 20 - 30 sec max
http://www.htmlite.com/php004.php

endif isn't used in normal everyday php. It may be used in one of the frameworks that implement MVC.

Return
You can use return in a function to return a value to the function call. The use of return is covered in the PHP manual. If you don't have a copy, get it. If you do have one, you need to use it.

Die
To quote the manual:
"This language construct is equivalent to exit()"
If you aren't familiar with exit, look it up in the manual.

To be a good programmer, you need to be reasonably self-sufficient. That means being able to search for what you need on the Internet and to use the manuals that are available. Yes, you need to understand how the various commands/verbs work but PHP is pretty well documented and has all kinds of info/examples/tutorials on the internet. It's usually a lot quicker and more effective to find the answers for yourself. PHP has been around for quite a long time and there are many thousands of people using it. All of the easy questions and most of the harder ones have been asked and answered already. It's all out there, you just have to use it.

Thanks. - The hyperlinked article is similar to others that I have already looked at (yes, I do use the search engines extensively) ...but is still a little vague on the subject. - I will do some further testing of more own and see if I can come up with something a little more precise.

The documentation on return is obscure to say the least. - That is why I was asking for help/clarification on the functionality of it. As I said earlier I have already tried testing it and could not find anything that I could use it with without it crashing our site.

die(), as I said, is something I have already successfully used and being self-sufficient is dependent entirely on the quality of available resources and on being able to understand those resources sufficiently to be able to be able to utilize them. As it stands the paucity of information necessary to be able to utilize said resources is the reason I am posting here, - I have better things to be doing than posting when I can find the answers without needing to.

Member Avatar for diafol

JB - don't bite the hand that's just fed you. php.net has a manual. There are millions of sites out there on php - I don't think that counts as paucity.

'return' is a common keyword in many languages for doing exactly what it says on the tin: return this (an value, variable, array, whatever) to the 'caller' from inside a function.

Your post suggests that you are very new to programming, so I'd suggest you buy some textbooks on php/MySQL. Online tutorials are all well and good, but they usually just include the code without too much explanation. Books should give more info. They try to teach as oppose to simply supplying info.

Here's a trivial usage of 'return':

function doAdd($num1, $num2){
  $ans = $num1 + $num2;
  return $ans;
}

echo doAdd(5,12); //will print 17 to the screen

Thanks, and thanks for the example.

I was being tetchy before because I usually spend many hours trying to work things out and searching the internet for answers before posting on the forum, so it annoys me when people answer my posts in ways that suggest "you are an obvious n00b who cannot be bothered to search for answers before posting"...

It is true that I have not done any serious programming for some time and do not bother with books so much now because they are all too often out of date, poorly written, or written by people with no real interest or knowledge and churned out purely for profit. Failing that the books take great pains to explain how to say "Hello World" and leave it at that ...so the end result is that it costs you a great deal of money (even buying used books) for very little of use that has not already been published on the web somewhere.

I would also agree that there are plenty of sites with information out there, but how many times have you searched for something only to find every site parroting the same lines copied from each other's sites or the manual? - Often you need something more in order to give you the required insight to do whatever it is that you are working on, and that is what I was refering to when I said about a paucity of information, so I guess what I should have said was a paucity of original content that demonstrated the code in use and not simply lines duplicated from elsewhere with no real knowledge of the content or whether the content actually works, etc..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.