var_export

PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8
var_export - Outputs or returns a parsable string representation of a variable
Manual
Code Examples

Example #1 Using __set_state()

Result: object(A)#2 (2) { ["var1"]=> int(5) ["var2"]=> string(3) "foo" }
PHP Version:

Example #2 var_export Examples

Result: array ( 0 => 1, 1 => 2, 2 => array ( 0 => 'a', 1 => 'b', 2 => 'c', ), )
PHP Version:

Example #3 Exporting stdClass (since PHP 7.3.0)

Result: (object) array( 'name' => 'ElePHPant ElePHPantsdotter', 'website' => 'https://php.net/elephpant.php', )
PHP Version:

Example #4 Exporting classes

Result: A::__set_state(array( 'var' => 5, ))
PHP Version:


Function var_export:

Variable handling Functions

Most used PHP functions