Home >Backend Development >PHP Tutorial >Implementation code for displaying arrays and objects in php_PHP tutorial
1. Use print_r ($array/$var)
print means printing, and r is taken from the word Array, then the function of this function is to print the contents of the array, and it can print the array Content, you can also print ordinary variables.
print_r ($_REQUEST) ;
print_r ($_GET) ; /* Print the form content passed using the GET method*/
print_r($_POST) ; /* Print the array passed using the form POST method Content*/
2. Use var_dump ($object/$array/$var)
var represents variable (Variable). Variables include objects, arrays and scalar variables. Dump has The meaning of "pour", combined, is to output all 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)
to output or return the character representation of a variable. This function returns structural information about the variables passed to the function. It is similar to print_r(), except that the representation returned is legal PHP code. You can return a representation of a variable by setting the second parameter of the function to TRUE.
For example: