English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP var_export() function usage and example

PHP available functions

var_export() function is used to output or return a variable as a string.

var_export() The function returns structural information about the variable passed to the function, it is similar to var_dump() Similar, but different is that it returns a valid PHP code.

PHP version requirement: PHP 4 => 4.2.0, PHP 5, PHP 7

Syntax

mixed var_export ( mixed $expression [, bool $return ] )

Parameter description:

  • $expression: The variable you want to output.
  • $return: Optional, if set to TRUE, the function will not execute the output result and will return the output result to a variable.

Return value

When $return is set to true, a return value is available, returning the structural information of the variable.

Online example

<?php
$a = array (1, 2, array ("a", "b", "c"));
var_export ($a);
?>

The output result is:

array (
  0 => 1,
  1 => 2,
  2 => 
  array (
    0 => 'a',
    1 => 'b',
    2 => 'c',
  ),
)

Optional parameter $return set to true:

<?php
$b = 3.1;
$v = var_export($b, TRUE);
echo $v;
?>

The output result is:

3.1

PHP available functions