May 10, 2021 PHP
PHP is the dynamic output of HTML content through print and echo statements, and although the functions of print and echo statements are almost exactly the same, there is a difference.
There are two basic output methods in PHP: echo and print.
In this section, we'll discuss in detail how to use both statements and demonstrate how to use echo and print in an example.
The difference between echo, print print_r and the file:
Tip: Echo outputs faster than print, echo is a PHP statement, no return value, print and print_r are PHP functions, functions have a return value.
The print return value is 1 (int type), print_r return value is true (bool type).
Echo is a language structure that can be used without parentheses or with parentheses: echo or echo().
The string is displayed
The following example shows how to output a string using the echo command (strings can contain HTML tags):
The variable is displayed
The following example shows how to output variables and strings using the echo command:
Print is also a language structure that can use parentheses or not: print or print().
The string is displayed
The following example shows how to output a string using the print command (strings can contain HTML tags):
The variable is displayed
The following example shows how to output variables and strings using the print command:
print_r displays easy-to-understand information about a variable, and if a string, integer, or float is given, the variable value itself is printed.
If array is given, keys and elements are displayed in a certain format. ject is similar to an array.
When using, you must put parentheses: print_r ()
.
Tip: The print_r () moves the pointer to the array to the last edge. U se reset() to get the pointer back to the beginning.
The string is displayed
The following example shows how to use print_r command output string(strings can contain HTML tags):
The variable is displayed
The following example shows how to use print_r command to output variables and strings:
In the next section, we'll look at the types of data in PHP.