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

PHP var_export function example explanation

怪我咯
怪我咯Original
2017-07-23 09:52:591610browse

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()打印的相似.

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;

The output form is as follows:

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

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!

Statement:
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