January 19, 201214 yr Hello, I'm just learning php at the moment and probably have a stupidly easy question!!! I'm getting confused on when 'echo' should be typed into a string or left out? Is there an easy way to remember when it needs to be included/left out? Gary
January 19, 201214 yr If you want something to be output, you need to use echo, print, or in more severe (last output moments) exit or die
January 19, 201214 yr Author If you want something to be output, you need to use echo, print, or in more severe (last output moments) exit or die Thanks. I haven't got to exit or die yet but sure they'll crop up soon.
January 19, 201214 yr They work in the same way really, with the exception that they terminate the code there and then
January 19, 201214 yr As a rule of thumb you should write your functions to return a value rather than echoing unless their sole purpose is to take an input, format it and echo it to the screen. The perfect function performs one job. It's fine to pass the output of one function to another function to format and echo, or just echo the returned value of a function with: echo my_function(); Edited January 19, 201214 yr by Renaissance-Design
Create an account or sign in to comment