🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ /** * var_export 格式化为5.4数组 */ function var_export_short($data, $return = true) { $dump = var_export($data, true); $dump = preg_replace('#(?:\A|\n)([ ]*)array \(#i', '[', $dump); // Starts $dump = preg_replace('#\n([ ]*)\),#', "\n$1],", $dump); // Ends $dump = preg_replace('#=> \[\n\s+\],\n#', "=> [],\n", $dump); // Empties if (gettype($data) == 'object') { // Deal with object states $dump = str_replace('__set_state(array(', '__set_state([', $dump); $dump = preg_replace('#\)\)$#', "])", $dump); } else { $dump = preg_replace('#\)$#', "]", $dump); } if ($return === true) { return $dump; } else { echo $dump; } } ~~~ ```php /** * var_export 格式化为5.4数组 */ function var_export54($var, $indent="") { switch (gettype($var)) { case "string": return '"' . addcslashes($var, "\\\$\"\r\n\t\v\f") . '"'; case "array": $indexed = array_keys($var) === range(0, count($var) - 1); $r = []; foreach ($var as $key => $value) { $r[] = "$indent " . ($indexed ? "" : var_export54($key) . " => ") . var_export54($value, "$indent "); } return "[\n" . implode(",\n", $r) . "\n" . $indent . "]"; case "boolean": return $var ? "TRUE" : "FALSE"; default: return var_export($var, TRUE); } } ```