Summary of var_export function and comparison with var_dump

WBOY
Release: 2016-07-29 09:12:25
Original
1032 people have browsed it

Recently, the original handwritten configuration file of the project has been moved to the management backend for easy configuration by others. This process uses the var_export function.

Summary:

1. According to official instructions, 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. This variable will obtain the same type of value as the one being var_exported, so the resource type cannot be simply copied. Therefore, when the variable of var_export is of resource type, var_export will return NULL. But var_dump will return the resource type.

//实验  
  $e = fopen("aa.php", "r");
  var_export($e);
  var_dump($e);
Copy after login

//运行结果
NULL
resource(3) of type (stream)
Copy after login
2. According to the official description, setting the second parameter to TRUE will return the representation of the variable.
$c = 'guugle';
  var_export($c); //直接打印出 'guugle'

  var_export($c, TRUE); //则无输出,返回变量表示
  $d = var_export($c, TRUE);
  echo $d; //输出 'guugle'
Copy after login

3. Var_export() generates configuration files for multiple users (var_export() will always retain structured data to store data)

$arr = array ( 1 , 2 , array ( "apple" , "banana" , "orange" )); 
  file_put_contents("aa.php", "<?php \n return ".var_export($arr, true)."\n?>"); //注意:需要加第二个参数TRUE返回变量的表示
Copy after login
results:

Summary of var_export function and comparison with var_dump


The above introduces the summary of the var_export function and its comparison with var_dump, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!