The function var_export() outputs or returns a parsable string representation of a variable. It is similar to var_dump() with one exception, the returned representation is valid PHP code.
string|null var_export ( mixed $value , bool $return = false )
Sr.No | Parameter | Description |
---|---|---|
1 |
value |
Mandatory.The variable you want to export. |
2 |
return |
Optional. If used and set to true, var_export() will return the variable representation instead of outputting it. |
This function returns the variable representation when the return parameter is set to true. Otherwise, this function will return null.
PHP 4.2 and above
Following example demonstrates use of var_export():
<?php $a = "Welcome TutorialsPoint!"; var_export($a); echo "<br>"; $b = array(2,'hello',22.99, array('a','b',2)); var_export($b); echo "<br>"; // Create a class class tutorialsPoint { public $tp_name = "Welcome to TutorialsPoint"; } // Create the class name alias class_alias('tutorialsPoint', 'TP'); $obj1 = new tutorialsPoint(); var_export($obj1); ?>
This will produce following result −
'Welcome TutorialsPoint!' array ( 0 => 2, 1 => 'hello', 2 => 22.99, 3 => array ( 0 => 'a', 1 => 'b', 2 => 2, ), ) tutorialsPoint::__set_state(array( 'tp_name' => 'Welcome to TutorialsPoint', ))