企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ /** * 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); } } ```