Difference Analysis of echo print_r and var_dump in PHP

  • 2021-07-21 07:35:14
  • OfStack

In this paper, the differences between echo, print_r and var_dump in PHP are analyzed in detail. Share it for your reference. The specific analysis is as follows:

All three are php statements with output function, but print_r (expression) and var_dump (expression) are functions, and echo is only a language structure, not a function, so it cannot be used as a part of the expression.

For the eight data types that operate on php:

① echo is used to output numeric variables or strings. However, when using echo to output reference variables, such as arrays, only the name of the array is output; When 1 object is output, the server prompts < Catchable fatal error: Object of class Person could not be converted to string > Error, error display echo can only be used to output strings.

② The function of print_r (expression) is to output an array. In fact, the type of parameter expression can be numeric variable and reference variable.

③ Output result of var_dump (expression) function < Variable type, variable value, variable length > The parameter expression represents various variable types and outputs the details of one variable.

I hope this article is helpful to everyone's PHP programming.


Related articles: