php Format Output File var_export Function Instance
- 2021-08-03 09:48:25
- OfStack
This article illustrates the usage of the var_export function in the php format output file. Share it for your reference. The details are as follows:
var_export:php 4 > = 4.2.0, php 5
var_export--Outputs or returns a string representation of a variable.
Description: mixed var_export (mixed expression [, bool return])
This function returns structural information about the variable passed to it, similar to var_dump (), except that the representation it returns is a legitimate php code, which you can return by setting the second argument of the function to true.
Example:
var_export(array('a','b',array('aa','bb','cc')))// This kind of relationship with var_dump That makes no difference
[code]$var =var_export(array('a','b',array('aa','bb','cc')),true)// Plus true Posterior , It won't print out again , But gave it to 1 Variable , So you can output directly ;
echo $var;// The output form at this time is the same as that of var_dump() Similarity of printing .
Example 2, 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',
),
)
I hope this article is helpful to everyone's PHP programming.