<?php
function varexport($expression, $return=FALSE, $indent=4) {
    $object = json_decode(str_replace(['(', ')'], ['&#40', '&#41'], json_encode($expression)), TRUE);
    $export = str_replace(['array (', ')', '&#40', '&#41'], ['[', ']', '(', ')'], var_export($object, TRUE));
    $export = preg_replace("/ => \n[^\S\n]*\[/m", ' => [', $export);
    $export = preg_replace("/ => \[\n[^\S\n]*\]/m", ' => []', $export);
    $spaces = str_repeat(' ', $indent);
    $export = preg_replace("/([ ]{2})(?![^ ])/m", $spaces, $export);
    $export = preg_replace("/^([ ]{2})/m", $spaces, $export);
    if ((bool)$return) return $export; else echo $export;
}
