Home > Backend Development > PHP Tutorial > PHP var_export function example explanation

PHP var_export function example explanation

怪我咯
Release: 2023-03-14 11:34:01
Original
1660 people have browsed it

The var_export() function returns structural information about the variable passed to the function. It is similar to var_dump(), except that the representation returned is legal PHP code. var_export must return legal PHP code. In other words, the code returned by var_export can be directly assigned to a variable as PHP code. And this variable will get the same type of value as var_export.

The example in this article describes the usage of the var_export function of the PHP format output file. Share it with everyone for your reference. The details are as follows:

var_export(array('a','b',array('aa','bb','cc')))//这种与var_dump没什么区别
[code]$var =var_export(array('a','b',array('aa','bb','cc')),true)//加上true后,不会再打印出来,而是给了一个变量,这样就可以直接输出; 
echo $var;//此时输出来的形式与var_dump()打印的相似.
Copy after login

Example 2, the code is as follows:

The code is as follows:

$data = array ('name' => 'abc', 'job' => 'programmer','a'=>array('aa','cc','bb'));  
$data = var_export($data,true);  
echo $data;
Copy after login

The output form is as follows:

array (  
'name' => 'abc',  
'job' => 'programmer',  
'a' => 
array (  
0 => 'aa',  
1 => 'cc',  
2 => 'bb',  
),  
)
Copy after login

The above is the detailed content of PHP var_export function example explanation. For more information, please follow other related articles on the PHP Chinese website!

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