Implementing code for displaying arrays and objects in PHP

Source: Internet
Author: User
Tags form post php script scalar smarty template

1. Using Print_r ($array/$var)
Print is the meaning of printing, and R is taken from the word array, then the function is to print the set of contents, it can be printed array content, you can also print ordinary variables.
Print_r ($_request);
Print_r ($_get); /* Print form content delivered using the Get method */
Print_r ($_post); /* Print array content passed using the form POST method */

2. Use Var_dump ($object/$array/$var)
var stands for variables (Variable), variables include objects, arrays, and scalar variables, and dump has the intention of pouring it out, adding it to the output of the contents of the variable or object.
Var_dump ($DB); /* Print the contents of the $DB database connection object */
Var_dump ($fileHandle); /* Print the contents of the file handle object */
Var_dump ($Smarty); /* Print Smarty Template Object */

3. Use Var_export ($object/$array/$var)
Outputs or returns the character representation of a variable. This function returns the structure information about the variable passed to the function, similar to Print_r (), unlike the PHP code whose returned representation is valid. You can return the representation of a variable by setting the second argument of the function to true.
For example:


<?php
$a = Array (Array ("A", "B", "C"));
Var_export ($a);
echo "<br>";
$v = Var_export ($a, TRUE);
Echo $v;
?>


In the example above, $v = Var_export ($a, TRUE) means that the source code of the PHP is returned, which can be directly used in the PHP script's array file.
Related instructions:
The above three functions can print the value of the object, the value of the system function, and the contents of the array;
echo, print, printf can print variable content, but cannot display arrays and system super variable arrays;
Print_r and Var_dump can not only print arrays, scalar variables, but also print the contents of objects;
The Var_dump statement can not only print variables, array contents, but also display the contents of Boolean variables and resources (RESOURCE);
The Var_export function returns the structure information about the variable passed to the function, similar to the Var_dump () function, and the difference is that the content it returns is a valid PHP code.

Implementing code for displaying arrays and objects in PHP

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.