Home  >  Article  >  Backend Development  >  PHP format output file var_export function example, _PHP tutorial

PHP format output file var_export function example, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:14:00847browse

PHP format output file var_export function example,

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:php 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 it returns is legal PHP code. You can do this by setting the second parameter of the function to true , thereby returning the representation of the variable.

Example:

Copy code The code is as follows:
var_export(array('a','b',array('aa',' bb','cc')))//This is no different from var_dump
[code]$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().

Example 2, the code is as follows:

Copy code 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:

Copy code The code is as follows:
array (
'name' => 'abc',
'job' => 'programmer',
'a' =>
array (
0 => 'aa',
1 => 'cc',
2 => 'bb',
),
)

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/912281.htmlTechArticlePHP format output file var_export function example. This example describes the usage of PHP format output file var_export function. Share it with everyone for your reference. The details are as follows: var_export:php...
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