Home > Backend Development > PHP Tutorial > Achieving common prosperity is the implementation code for displaying arrays and objects in PHP

Achieving common prosperity is the implementation code for displaying arrays and objects in PHP

WBOY
Release: 2016-07-29 08:44:53
Original
1139 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 array content. It can print the array content or ordinary variables. .
print_r ($_REQUEST);
print_r ($_GET); /* Print the form content passed using the GET method*/
print_r($_POST); /* Print the array content passed using the form POST method*/
2. Use var_dump ($object/$array/$var)
var represents variable (Variable). Variables include objects, arrays and scalar variables. Dump means dumping. When added together, all the contents of variables or objects are output. .
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 the 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 returned PHP source code can be directly used in the array file of the PHP script.
Related instructions:
The above three functions can all print object values, system function values, and array contents;
△ echo, print, and printf can print variable contents, but cannot display arrays and system super variable 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 the information passed to the The structure information of the function's variables is similar to the var_dump() function, except that the content returned is legal PHP code.

The above introduces the implementation code for displaying arrays and objects in PHP to realize common prosperity, including the content of realizing common prosperity. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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