var_export

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,
))

print_r

var_dump

boolval

debug_zval_dump

doubleval

empty

floatval

get_debug_type

get_defined_vars

get_resource_id

get_resource_type

gettype

intval

is_array

is_bool

is_callable

is_countable

is_double

is_float

is_int

is_integer

is_iterable

is_long

is_null

is_numeric

is_object

is_real

is_resource

is_scalar

is_string

isset

print_r

serialize

settype

strval

unserialize

unset

var_dump

PHP

Home Menu