Arrays are a type of variables in PHP and are often used in PHP development. Therefore, it is very important to print the array content using PHP statements.
Arrays are a type of variables in PHP and are often used in PHP development. Therefore, it is very important to print the array content using PHP statements.
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 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.
For example:
The Code is as follows:
$ 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 and can be directly used in the array file of the PHP script.
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.