Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

var_export()

var_export() is a PHP native function that produces a representation of the passed data as PHP code.

var_export() is used for caching, by storing an intermediate result for later inclusion. var_export() is also used for storing PHP data, and later accessing them in their current form: it bypasses the process of serializing/unserializing by using PHP as the serialization itself.

var_export() is usually replaced by print_r(), var_dump() or other adapted functions when it is immediately displayed, during a development session.

<?php

    print var_export(1); // 1
    
    print var_export(abc); // 'abc'
    
    $a = [1, 3, 4];
    $a[] = 5;
    print var_export($a); // 
    
    class Elephpant {
        public string $p = 'yes';
    }

    $trunk = new Elephpant();
    $trunk->p = 'PHP rocks';
    print var_export($a); //

?>

Documentation

See Also