3v4l.org

run code in 300+ PHP versions simultaneously
<?php function var_export_2($thing) { $code1 = var_export($thing, true); $code2 = ''; $tokens = token_get_all('<?php ' . $code1); for ($i = 0, $imax = count($tokens); $i < $imax; $i++) { $token = $tokens[$i]; switch ($token[0]) { case '(': $token = '['; break; case ')': $token = ']'; break; case T_ARRAY: $i++; continue 2; case T_OPEN_TAG: continue 2; } $code2 .= is_array($token) ? $token[1] : $token[0]; } return $code2; } echo var_export_2(['a', 'b', 'c', 'd' => ['e', 'f', 'g' => [1, 2, 3]]]);

preferences:
26.91 ms | 405 KiB | 5 Q