Differences in the usage of print_r, var_dump, and var_export functions in php

Source: Internet
Author: User
Tags echo command form post
What are the usage differences between print_r, var_dump, and var_export functions in php? print_r ($ array $ var )? Print indicates the meaning of printing, and r is taken from the word of Array. then, this function is used to print the Array content. it can print both the Array content and common variables .? Print_r ($ _ REQUEST );? Print_r ($ _ GET); * differences in the usage of print_r, var_dump, and var_export functions in php

, Print_r ($ array/$ var )?
Print indicates the meaning of printing, and r is taken from the word of Array. then, this function is used to print the Array content. it can print both the Array content and common variables .?
Print_r ($ _ REQUEST );?
Print_r ($ _ GET);/* print the content of the form passed using the GET method */?
Print_r ($ _ POST);/* print the array content passed through the form POST method */?
2. var_dump ($ object/$ array/$ var )?
Var represents a Variable (Variable). a Variable includes an object, an array, and a scalar Variable. dump has the intention of reversing it. In addition, it outputs all the content of a Variable or object .?
Var_dump ($ DB);/* print the content of the $ DB database connection object */?
Var_dump ($ fileHandle);/* print the content of the file handle object */?
Var_dump ($ Smarty);/* print the Smarty template object */?
3. var_export ($ object/$ array/$ var )?
Output or return the character representation of a variable. This function returns structure information about the variables passed to the function. it is similar to print_r (). The difference is that the returned representation is legal PHP code. You can set the second parameter of the function to TRUE to return the expression of the variable .?
See the following code :?
$ A = array (1, 2, array ("a", "B", "c "));?
Var_export ($ );?
Echo"
";?
$ V = var_export ($ a, TRUE );?
Echo $ v ;?
?>?
In the preceding example, $ v = var_export ($ a, TRUE) indicates that the PHP source code is returned. you can directly use the array file of the PHP script .?
Summary :?
All the above three functions can print the object value, system function value, and array content ;?
1. echo, print, and printf can print variable content, but cannot display arrays and system super variable arrays ;?
2. print_r and var_dump can print not only arrays and scalar variables, but also Object Content ;?
3. the var_dump statement not only prints variables and arrays, but also displays Boolean variables and resources ;?
4. the var_export function returns the structure information about the variables passed to the function. similar to the var_dump () function, the difference is that the returned content is legal PHP code.

?

?

?

?

?

What is the difference between echo and print in php .?
Echo description :?
Echo can output multiple strings at the same time without parentheses ;?
Echo is more like a statement ;?
Echo;? is recommended ;?
Echo 'and so on. I haven't finished writing it yet. Click here. ';?
?>?
Echo () has no return value, which is the same as the echo command ;?
Echo can have multiple parameters. echo has no return value .?

Print description :?
Print can only output one string at a time, and parentheses are required. ?
Print is a function ;?
The usage of print is similar to that of C language, so it will make a special explanation of % in the output content ;?
There is no big difference. it's just a function and a command .?
Can print be used like this?
Print < ?
?
?
Php self-learning network?
?
?
?
?
DND?
?>?
In this way, you can output a large HTML segment without escaping the quotation marks?
Automatically replace the variables in it?
Print a parameter. print has, true, 1; false, 0 .?
Difference details :?
There is no difference between the echo command and the print command ;?
The echo function differs from the print function ;?
Print () has a returned value. if the execution fails (such as disconnection), flase ;?
Both printf () and sprintf () are formatted outputs. The difference is that the former is output to the standard output, and the latter is output to the variable .?
Use in the same page < <标记,标记名为配对出现,同一页面中不允许同名出现两个以上标记名。配对标记名的结尾标记名应单独一行,前后均不允许输出字符...(例如空格等不可见但存在的字符..) 。?
Like?
Echo <EOT?
EOT ;?
Print <EOT?
EOT ;?
The description of the format is as follows :?
<Operator, which treats the content between custom delimiters as a string and can be used to process the variables in it?
EOT user-defined delimiters. the end must be at the beginning of the line.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.