Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

var_export

Prints a value as PHP code.

Syntax

var_export(mixed $value, bool $return = false): ?string

Parameters

ParameterTypeDescription
$valuemixedThe value.
$returnboolOptional. `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

  • var_dump — Prints the type and the value — for debugging.
  • print_r — Prints a value in a readable form.
  • serialize — Turns a value into a string for storage.

In the tutorial

  • Errors and debugging — The kinds of PHP errors, error display settings, the log, turning warnings into exceptions and debugging techniques.

Thanks for reading!

Donate to the site — we work hard for you.