PHP displays the implementation code of arrays and objects

Source: Internet
Author: User
Tags smarty template

1. Use print_r ($ array/$ var)
Print is the meaning of printing, and R is taken from the word of array. The function is 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. Use 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. Use var_export ($ object/$ array/$ var)
Output or return the character representation of a variable. This function returns the structure information about the variables passed to the function. It is similar to print_r (). The difference is that the returned representation is legal in PHP.Code. You can set the second parameter of the function to true to return the expression of the variable.
For example:Copy codeThe Code is as follows: <? PHP
$ A = array (1, 2, array ("A", "B", "C "));
Var_export ($ );
Echo "<br> ";
$ V = var_export ($ A, true );
Echo $ V;
?>

In the preceding example, $ v = var_export ($ A, true) indicates that PHP returnsSource code, You can directly use the PHP script in the array file.
Instructions:
The preceding three functions can print the object value, system function value, and array content;
△Echo, print, and printf can print variable content, but cannot display arrays and system super variable arrays;
△Print_r and var_dump can print not only arrays and scalar variables, but also object content;
△Var_dump statement can not only print variables and array content, but also display the content of Boolean variables and resources;
△ 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.

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.