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