1 2 3 4 5 6 7 8 9 10 | <?php function varexport($expression, $return=FALSE) { $export = var_export($expression, TRUE); $export = preg_replace("/^([ ]*)(.*)/m", '$1$1$2', $export); $array = preg_split("/\r\n|\n|\r/", $export); $array = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [NULL, ']$1', ' => ['], $array); $export = join(PHP_EOL, array_filter(["["] + $array)); if ((bool)$return) return $export; else echo $export; } |
PHP var_export() with short array syntax (square brackets) indented 4 spaces ยท GitHub
gist.github.com