Home >Backend Development >PHP Tutorial >Output legal php format files var_export_PHP tutorial
var_export
(php tutorial 4 >= 4.2.0, php 5)
var_export -- Export or return a string representation of a variable
Description
mixed var_export ( mixed expression [, bool return] )
This function returns structural information about the variables passed to the function. It is similar to var_dump(), 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.
eg:
var_export(array('a','b',array('aa','bb','cc'))) This is no different from var_dump;
$var =var_export(array('a','b',array('aa','bb','cc')),true), after adding true, it will not be printed anymore, but A variable is given so that it can be output directly;
echo $var;The output form at this time is similar to that printed by var_dump().
eg2
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 format is as follows:
The code is as follows:
array (
'name' => 'abc',
'job' => 'programmer',
'a' =>
array (
0 => 'aa',
1 => 'cc',
2 => 'bb',
),
)