Home > Backend Development > PHP Tutorial > Implementation code for displaying arrays and objects in php_PHP tutorial

Implementation code for displaying arrays and objects in php_PHP tutorial

WBOY
Release: 2016-07-21 15:30:45
Original
787 people have browsed it

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:

Copy code The code is as follows:

$a = array ( 1 ,2, array("a","b","c")) ;
var_export ($a) ;
echo "
" ;
$v = var_export ( $a , TRUE) ;
echo $v ;
?>

In the above example, $v = var_export ( $a , TRUE) means that the source code of PHP is returned, which can be directly Array file using PHP script.
Related instructions:
The above three functions can print the value of the object, the value of the system function and the content of the array;
△ echo, print, and printf can print the content of the variable, but cannot display the array and system super variables Arrays;
△ print_r and var_dump can not only print arrays and scalar variables, but also the contents of objects;
△ The var_dump statement can not only print variables and array contents, but also display the contents of Boolean variables and resources. ;
△ The var_export function returns structural information about the variables passed to the function. It is similar to the var_dump() function, except that the content returned is legal PHP code.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323131.htmlTechArticle1. Use print_r ( $array/$var ) print means printing, and r is taken from Array word, then the function of this function is to print the array content. It can print the array content or...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template