The difference between echo, print and print_r

the difference:

①echo is a language structure, not a function or method. It can be used without parentheses, and is mostly used for single-line string output. The efficiency I remember is higher than print().
②print() is also a single-line output, but it is a function. When using it, a string should be passed as a parameter to the print() function. Some server-side programs are written in PHP, and the output will use print(); instead of echo; I don't know the reason for this...
③print_r () A function that can be used to traverse and output an array, I am usually debugging Used to view the contents of the array in the process of the program. Can also be used to output a single string. Generally only used in the process of debugging the program. After the program is written, this stuff should be removed.

 

Other explanations:

(1) Both echo and print can do output. The difference is that echo is not a function and has no return value, while print is a function with return value, so relatively speaking, it will be faster to output echo, and print_r is usually used to print Information about variables, usually used in debugging.
(2) print is to print strings
(3) print_r is to print composite types such as array objects

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326187424&siteId=291194637