var_export
Prints a value as PHP code.
Syntax
var_export(mixed $value, bool $return = false): ?stringParameters
| Parameter | Type | Description |
|---|---|---|
| $value | mixed | The value. |
| $return | bool | Optional. `true` returns the text. |
Return value
?stringA string with the code when the second argument is set.
Examples
The result can be pasted into a program:
<?php
var_export(['name' => 'Anna', 'active' => true]);Output:
array (
'name' => 'Anna',
'active' => true,
)Notes
This is how settings are saved to a code file: file_put_contents('config.php', '<?php return ' . var_export($config, true) . ';').
See also
In the tutorial
- Errors and debugging — The kinds of PHP errors, error display settings, the log, turning warnings into exceptions and debugging techniques.