Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

var_export

Description

Outputs or returns a parsable string representation of a variable

Syntax

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

Parameters

value

The variable to export.

return

If used and set to true, var_export() will return the variable representation instead of outputting it.

Return

Returns the variable representation when the return parameter is used and evaluates to true. Otherwise, this function will return null.

Examples

1 · value · bool

<?

$value = false;

var_export($value);

?>
false

2 · value · int

<?

$value = 0;

var_export($value);

?>
0

3 · value · float

<?

$value = 0.0;

var_export($value);

?>
0.0

4 · value · string

<?

$value = "0";

var_export($value);

?>
'0'

5 · value · array

<?

$value = array(0, 1, array(0, 1));

var_export($value);

?>
array (
  0 => 0,
  1 => 1,
  2 => 
  array (
    0 => 0,
    1 => 1,
  ),
)

6 · value · object · standard class

<?

$value = new stdclass;
$value->var = 0;

var_export($value);

?>
(object) array(
   'var' => 0,
)

7 · value · object · custom class

<?

class myclass
{
    public $var;
}

$value = new myclass;
$value->var = 0;

var_export($value);

?>
\myclass::__set_state(array(
   'var' => 0,
))

8 · return · false

<?

class myclass
{
    public $var;
}

$value = new myclass;
$value->var = 0;
$return = false;

$output = var_export($value, $return);

echo PHP_EOL . "output:" . PHP_EOL;
var_export($output);

?>
\myclass::__set_state(array(
   'var' => 0,
))
output:
NULL

9 · return · true

<?

class myclass
{
    public $var;
}

$value = new myclass;
$value->var = 0;
$return = true;

$output = var_export($value, $return);

echo "output:" . PHP_EOL . $output;

?>
output:
\myclass::__set_state(array(
   'var' => 0,
))
HomeMenu