PHP display array and object implementation code _php tips

Source: Internet
Author: User
Tags form post php script scalar smarty template
1. Use Print_r ($array/$var)
Print is the meaning of printing, and R is taken from the array of words, then the function is to play a set of content, it can either print the contents of the array, you can print the ordinary variables.
Print_r ($_request);
Print_r ($_get); /* Print form content that is passed using the Get method.
Print_r ($_post); /* Print the contents of the array passed with the form POST method * *

2. Use Var_dump ($object/$array/$var)
var represents a variable (Variable), a variable that includes an object, an array, and a scalar variable, and the dump has an inverted meaning, added to it, that is, the contents of the variable or object are all exported.
Var_dump ($DB); /* Print the contents of the $DB database connection object * *
Var_dump ($fileHandle); /* The contents of the print file handle Object * *
Var_dump ($Smarty); /* Print Smarty Template Object * *

3. Use Var_export ($object/$array/$var)
The character representation of the output or return of a variable. This function returns the structure information about the variable passed to the function, which is similar to Print_r (), and differs from its return representation as a valid PHP code. You can return the representation of a variable by setting the second argument of the function to true.
For example:
Copy Code code as follows:

$a = Array (1,2, 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) indicates that the source code of PHP is returned, which can be used directly in the PHP script's array file.
Related instructions:
All three of these functions can print the value of the object, the value of the system function, and the contents of the array;
echo, print, and printf can print variable content, but cannot display array and system super variable array;
Print_r and Var_dump can not only print arrays, scalar variables, but also print the contents of objects;
Var_dump statements can not only print variables, array contents, but also display the contents of Boolean variables and resources (RESOURCE);
The Var_export function returns the structural information about the variable passed to the function, similar to the Var_dump () function, and the difference is that the returned content is valid PHP code.
Related Article

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: 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.