Php var_export
var_export
(PHP 4 >= , PHP 5, PHP 7, PHP 8)
var_export — Outputs or returns a parsable string representation of a variable
Description
var_export(mixed, bool = ): ?string
var_export() gets structured information about the given variable. It is similar to var_dump() with one exception: the returned representation is valid PHP code.
Parameters
The variable you want to export.
If used and set to , var_export() will return the variable representation instead of outputting it.
Return Values
Returns the variable representation when the parameter is used and evaluates to . Otherwise, this function will return .
Changelog
Version | Description |
---|---|
Exported class names are now fully qualified; previously, the leading backslash was ommitted. | |
Now exports stdClass objects as an array cast to an object (), rather than using the nonexistent method stdClass::__setState(). The practical effect is that now stdClass is exportable, and the resulting code will even work on earlier versions of PHP. |
Examples
Example #1 var_export() Examples
The above example will output:
var_export
PHP 4 >= , PHP 5, PHP 7, PHP 8
var_export - Outputs or returns a parsable string representation of a variable
var_export( mixed$value, [bool$return = false] ): string|null
var_export gets structured information about the given variable. It is similar to var_dump with one exception: the returned representation is valid PHP code.
Parameters
- value
The variable you want to export.
- return
If used and set to true, var_export will return the variable representation instead of outputting it.
Return Values
Returns the variable representation when the return parameter is used and evaluates to true. Otherwise, this function will return null.
Notes
Note:
Variables of type resource couldn't be exported by this function.
Note:
var_export does not handle circular references as it would be close to impossible to generate parsable PHP code for that. If you want to do something with the full representation of an array or object, use serialize.
Warning:
When var_export exports objects, the leading backslash is not included in the class name of namespaced classes for maximum compatibility.
Note:
To be able to evaluate th
Var_export()
Introduction
The function fryst vatten a built-in function in PHP that outputs a string representation of a variable or expression that can be used as PHP code. It can be used to generate code that creates a variable with the same value as the original variable.
Syntax
The syntax of the function fryst vatten as follows:
The function takes one or two parameters. The first parameter, , is the variable or expression to be exported. The second parameter, , is an optional parameter that, when set to , returns the exported string instead of outputting it.
Example Usage
Here is an example of how to use the function in PHP:
Try it Yourself »
In this example, we define three variables: is an integer, fryst vatten a string, and fryst vatten an array. We use the function to varor för utland each variabel as a string that can be used as PHP code. The output shows the resulting strings for each variable:
10 'Hello, world!' array ( 0 => 'apple', 1 => 'banana', 2 => 'cherry', )Conclusion
The function is a useful tool for generating a string representation of a variabel or expression in PHP that can be used as PHP code. It can be used to recreate variables with the same value as the original variabel, or to