|
|
 |
var_export (PHP 4 >= 4.2.0, PHP 5) var_export -- 输出或返回一个变量的字符串表示 描述mixed var_export ( mixed expression [, bool return])
此函数返回关于传递给该函数的变量的结构信息,它和
var_dump() 类似,不同的是其返回的表示是合法的
PHP 代码。
您可以通过将函数的第二个参数设置为
TRUE,从而返回变量的表示。
比较 var_export() 和
var_dump().
php_manual_note at bigredspark dot com
16-Oct-2003 03:43
[john holmes]
True, but that method would require you to open and read
the file into a variable and then unserialize it into another
variable.
Using a file created with var_export() could simply be
include()'d, which will be less code and faster.
[kaja]
If
you are trying to find a way to temporarily save variables into some other
file, check out serialize() and unserialize() instead - this one is more
useful for its readable property, very handy while
debugging.
[original post]
If you're like me, you're wondering
why a function that outputs "correct PHP syntax" is useful. This
function can be useful in implementing a cache system. You can var_export()
the array into a variable and write it into a file. Writing a string such
as
<?php
$string = '<?php $array = ' . $data . ';
?>';
?>
where $data is the output of var_export() can
create a file that can be easily include()d back into the script to
recreate $array.
The raw output of var_export() could also be
eval()d to recreate the array.
---John Holmes...
| |