Magento tips
- 18439 vues -

Php echo and print statements

There are two fundamental ways to get output with PHP: echo and print. Echo and printing are more or less identical. Both are used to output screen data. The differences are small: echo does not have a return value while print has a return value of 1 so that it can be used in terms. Echo may take multiple parameters (although rare) while printing may take one argument. Echo is slightly faster than printing.

The PHP echo Statement

One or more strings can be output from the echo statement. Generally speaking, the echo statement can display anything that can be displayed to the browser, such as string, numbers, variables, expressions results, etc. Since echo is a language construct that is not actually a function (like ‘if’ statement), it can be used without parentheses, e.g. echo or echo). If you want to pass more than one parameter to echo, however, you must not include the parameters within parentheses. Instead of a single string reasoning, we can transfer various string statements to the echo declaration and separate them by comma (', ') operator. For instance, if we have two strings that say "Hello" and "World," we can pass them as ("Hello,""World")

The PHP print Statement

You can also use the print statement to display output to the browser (an alternative to echo). Like echo, printing is not a real function, but a language construct. Without parentheses like: print or print), (you can also use it. Both the echo statement and the print statement work the same way except that the print statement can only output one string and always return 1. That's why the echo statement was considered marginally faster than the print statement as it returns no value. In the same manner we did with echo statements, we can show strings with print declaration. The only difference is that with a single print statement, we cannot show various strings distinguished by comma,). The instance below demonstrates how to use PHP print declaration to show strings. Thanks to custom php application developmentthis is possible.

Developper blog

  1. 15 Oct. 20217 Things You Need to Know About PHP Solutions109 vues
  2. 23 Août 202110 Skills PHP Web Developers Must Have to Succeed in the Industry211 vues
  3. 17 Mai 2021Learn how to become a good programmer281 vues
  4. 18 Avril 2021Which VPS plan is best for you ?511 vues
  5. 9 Mars 2021Do your frameworks with PHP specialists582 vues
  6. 25 Fév. 2021Analyze your future audience and build your website968 vues
  7. 27 Janv. 202180% of websites all over the Internet are built with PHP1001 vues
  8. 17 Nov. 2020Php developers who can take your project to the next level1211 vues