3v4l.org

run code in 300+ PHP versions simultaneously
<?php function JSEscape($s) { static $aSearch = array("\xe2\x80\xa9", "\\", "'", "\"", "\r\n", "\r", "\n", "\xe2\x80\xa8", "*/", "</"); static $aReplace = array(" ", "\\\\", "\\'", '\\"', "\n", "\n", "\\n", "\\n", "*\\/", "<\\/"); $val = str_replace($aSearch, $aReplace, $s); return $val; } function PhpToJSObject($arData, $bWS = false, $bSkipTilda = false, $bExtType = false) { static $aSearch = array("\r", "\n"); $bExtType = !!$bExtType; if(is_array($arData)) { $i = -1; $j = -1; if (!empty($arData)) { foreach($arData as $j => $temp) { $i++; if ($j !== $i) break; } } if($j === $i) { foreach($arData as $key => $value) { if(is_string($value)) { if(preg_match("#['\"\\n\\r<\\\\\x80]#", $value)) $arData[$key] = "'".JSEscape($value)."'"; else $arData[$key] = "'".$value."'"; } elseif(is_bool($value)) { if($value === true) $arData[$key] = 'true'; else $arData[$key] = 'false'; } elseif(is_array($value)) { $arData[$key] = PhpToJSObject($value, $bWS, $bSkipTilda, $bExtType); } elseif ($bExtType && (is_int($value) || is_float($value))) { $arData[$key] = $value; } else { if(preg_match("#['\"\\n\\r<\\\\\x80]#", $value)) $arData[$key] = "'".JSEscape($value)."'"; else $arData[$key] = "'".$value."'"; } } return '['.implode(',', $arData).']'; } $sWS = ','.($bWS ? "\n" : ''); $res = ($bWS ? "\n" : '').'{'; $first = true; foreach($arData as $key => $value) { if ($bSkipTilda && substr($key, 0, 1) == '~') continue; if($first) $first = false; else $res .= $sWS; if(preg_match("#['\"\\n\\r<\\\\\x80]#", $key)) $res .= "'".str_replace($aSearch, '', JSEscape($key))."':"; else $res .= "'".$key."':"; if(is_string($value)) { if(preg_match("#['\"\\n\\r<\\\\\x80]#", $value)) $res .= "'".JSEscape($value)."'"; else $res .= "'".$value."'"; } elseif(is_bool($value)) { if($value === true) $res .= 'true'; else $res .= 'false'; } elseif(is_array($value)) { $res .= PhpToJSObject($value, $bWS, $bSkipTilda, $bExtType); } elseif ($bExtType && (is_int($value) || is_float($value))) { $res .= $value; } else { if(preg_match("#['\"\\n\\r<\\\\\x80]#", $value)) $res .= "'".JSEscape($value)."'"; else $res .= "'".$value."'"; } } $res .= ($bWS ? "\n" : '').'}'; return $res; } elseif(is_bool($arData)) { if($arData === true) return 'true'; else return 'false'; } elseif ($bExtType && (is_int($arData) || is_float($arData))) { return $arData; } else { if(preg_match("#['\"\\n\\r<\\\\\x80]#", $arData)) return "'".JSEscape($arData)."'"; else return "'".$arData."'"; } } $a=array( "a0" => "b", "a1" => "b", "a2" => "b", "a3" => "b", "b" => "c'", "c" => array(1,2,3), "d" => true, "e" => 15.5 ); print_r(PhpToJSObject($a));

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0070.00717.00
8.3.50.0170.00423.07
8.3.40.0120.00318.95
8.3.30.0070.00719.04
8.3.20.0040.00420.29
8.3.10.0050.00323.45
8.3.00.0050.00319.38
8.2.180.0070.01016.63
8.2.170.0070.00722.96
8.2.160.0060.01020.64
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0080.00020.88
8.2.110.0100.00022.13
8.2.100.0080.00418.34
8.2.90.0040.00719.33
8.2.80.0040.00417.97
8.2.70.0060.00317.86
8.2.60.0000.00918.04
8.2.50.0000.00818.07
8.2.40.0050.00320.20
8.2.30.0040.00418.27
8.2.20.0000.00817.94
8.2.10.0000.00818.27
8.2.00.0040.00417.90
8.1.280.0090.00625.92
8.1.270.0050.00323.96
8.1.260.0050.00326.35
8.1.250.0070.00028.09
8.1.240.0050.00522.08
8.1.230.0000.01118.89
8.1.220.0050.00317.80
8.1.210.0000.00818.77
8.1.200.0050.00517.60
8.1.190.0000.00917.60
8.1.180.0080.00018.10
8.1.170.0070.00318.68
8.1.160.0070.00022.02
8.1.150.0030.00618.97
8.1.140.0000.01017.70
8.1.130.0000.00717.86
8.1.120.0040.00417.70
8.1.110.0040.00417.56
8.1.100.0000.00717.58
8.1.90.0040.00417.71
8.1.80.0080.00017.63
8.1.70.0000.00717.61
8.1.60.0040.00417.77
8.1.50.0080.00017.66
8.1.40.0060.00317.75
8.1.30.0000.00817.76
8.1.20.0030.00617.88
8.1.10.0080.00017.82
8.1.00.0040.00417.74
8.0.300.0040.00418.77
8.0.290.0080.00017.00
8.0.280.0050.00218.42
8.0.270.0040.00417.36
8.0.260.0030.00317.30
8.0.250.0070.00017.07
8.0.240.0000.00817.06
8.0.230.0040.00417.16
8.0.220.0030.00317.00
8.0.210.0020.00517.09
8.0.200.0070.00017.05
8.0.190.0030.00617.06
8.0.180.0040.00417.06
8.0.170.0000.00917.02
8.0.160.0080.00017.15
8.0.150.0040.00416.95
8.0.140.0050.00317.04
8.0.130.0030.00313.57
8.0.120.0060.00317.08
8.0.110.0050.00316.98
8.0.100.0040.00417.05
8.0.90.0000.00817.15
8.0.80.0100.00717.16
8.0.70.0070.00017.06
8.0.60.0040.00417.01
8.0.50.0060.00316.94
8.0.30.0080.01217.40
8.0.20.0130.00617.40
8.0.10.0000.00817.19
8.0.00.0080.00917.01
7.4.330.0000.00515.16
7.4.320.0030.00316.87
7.4.300.0040.00416.69
7.4.290.0000.00716.79
7.4.280.0030.00616.91
7.4.270.0030.00616.87
7.4.260.0040.00416.88
7.4.250.0030.00516.71
7.4.240.0010.00616.89
7.4.230.0000.00816.96
7.4.220.0060.01316.70
7.4.210.0040.01116.87
7.4.200.0050.00316.97
7.4.160.0100.00716.70
7.4.150.0150.00417.40
7.4.140.0110.00717.86
7.4.130.0090.00816.78
7.4.120.0080.00916.68
7.4.110.0090.00916.92
7.4.100.0110.00716.95
7.4.90.0090.00916.77
7.4.80.0060.01619.39
7.4.70.0060.01216.61
7.4.60.0070.01116.87
7.4.50.0040.00016.57
7.4.40.0070.01416.83
7.4.30.0040.01216.97
7.4.00.0110.00415.09
7.3.330.0060.00013.57
7.3.320.0060.00013.36
7.3.310.0000.00716.59
7.3.300.0000.00716.65
7.3.290.0060.01016.62
7.3.280.0080.00716.60
7.3.270.0030.01517.40
7.3.260.0030.01616.71
7.3.250.0080.01016.86
7.3.240.0110.00716.53
7.3.230.0150.00316.61
7.3.210.0190.00316.79
7.3.200.0140.00419.39
7.3.190.0090.00616.82
7.3.180.0060.00916.84
7.3.170.0110.01116.85
7.3.160.0140.00316.66
7.2.330.0070.01316.76
7.2.320.0000.01917.05
7.2.310.0040.01617.07
7.2.300.0110.00516.83
7.2.290.0030.01316.88
7.1.70.0050.00317.46
7.1.60.0100.01319.46
7.1.50.0110.01117.12
7.1.00.0070.08722.55
7.0.200.0000.00916.92
7.0.140.0000.07722.00
7.0.60.0100.08319.93
7.0.50.0030.04317.94
7.0.40.0030.04320.14
7.0.30.0230.03720.30
7.0.20.0100.04720.08
7.0.10.0000.09320.32
7.0.00.0070.08720.10
5.6.280.0030.07721.07
5.6.210.0070.08720.66
5.6.200.0070.08718.20
5.6.190.0070.05020.57
5.6.180.0000.09720.60
5.6.170.0270.07720.51
5.6.160.0100.08320.71
5.6.150.0000.04718.29
5.6.140.0130.07718.23
5.6.130.0070.08018.20
5.6.120.0100.08721.18
5.6.110.0070.08021.00
5.6.100.0030.04021.01
5.6.90.0000.08021.00
5.6.80.0130.06020.45
5.6.70.4400.03020.48
5.5.350.0070.07320.37
5.5.340.0230.04018.05
5.5.330.0130.08020.57
5.5.320.0100.05020.28
5.5.310.0230.06320.39
5.5.300.0100.08318.08
5.5.290.0030.05017.98
5.5.280.0000.04320.92
5.5.270.0130.07320.81
5.5.260.0200.07020.93
5.5.250.0130.07720.66
5.5.240.0270.07020.31
5.4.450.0230.03319.57
5.4.440.0270.04319.20
5.4.430.0370.04719.30
5.4.420.0200.04319.48
5.4.410.0330.03719.25
5.4.400.0270.05318.96
5.4.390.0300.03719.00
5.4.380.0330.07018.58
5.4.370.0230.06318.79
5.4.360.0500.03718.61
5.4.350.0400.06318.61
5.4.340.0530.06318.62
5.4.320.0090.03312.55
5.4.310.0070.03712.55
5.4.300.0080.03512.55
5.4.290.0060.04112.55
5.4.280.0050.03812.45
5.4.270.0080.03612.45
5.4.260.0090.03712.45
5.4.250.0070.03812.45
5.4.240.0060.04012.45
5.4.230.0060.03812.44
5.4.220.0080.03412.44
5.4.210.0060.03512.44
5.4.200.0030.04012.43
5.4.190.0080.03312.44
5.4.180.0050.03612.44
5.4.170.0050.03712.44
5.4.160.0050.03612.44
5.4.150.0060.03612.44
5.4.140.0070.03612.11
5.4.130.0040.03712.11
5.4.120.0060.03412.06
5.4.110.0040.04112.06
5.4.100.0090.04012.06
5.4.90.0060.03712.06
5.4.80.0080.03612.06
5.4.70.0080.03312.05
5.4.60.0060.03612.05
5.4.50.0080.03412.06
5.4.40.0090.03212.04
5.4.30.0030.03812.04
5.4.20.0060.03512.04
5.4.10.0040.03612.04
5.4.00.0050.03711.53
5.3.290.0110.03412.80
5.3.280.0080.03612.72
5.3.270.0050.03912.73
5.3.260.0060.03812.73
5.3.250.0030.04012.73
5.3.240.0080.04412.73
5.3.230.0050.03912.72
5.3.220.0070.03612.69
5.3.210.0090.04112.69
5.3.200.0070.03512.69
5.3.190.0040.04312.69
5.3.180.0040.03812.69
5.3.170.0070.03512.69
5.3.160.0040.03812.69
5.3.150.0030.03912.69
5.3.140.0060.03512.68
5.3.130.0070.04112.67
5.3.120.0050.04012.68
5.3.110.0060.03812.67
5.3.100.0050.03712.16
5.3.90.0050.03612.14
5.3.80.0050.03712.14
5.3.70.0050.04112.14
5.3.60.0030.03812.12
5.3.50.0040.03712.07
5.3.40.0060.03612.09
5.3.30.0060.03412.03
5.3.20.0100.03711.81
5.3.10.0060.03411.77
5.3.00.0040.03711.76
5.2.170.0050.0349.27
5.2.160.0050.0289.27
5.2.150.0070.0279.26
5.2.140.0040.0309.26
5.2.130.0040.0299.22
5.2.120.0040.0289.22
5.2.110.0030.0309.23
5.2.100.0100.0289.23
5.2.90.0050.0289.23
5.2.80.0030.0329.22
5.2.70.0050.0309.22
5.2.60.0030.0319.18
5.2.50.0060.0289.15
5.2.40.0080.0319.14
5.2.30.0090.0269.11
5.2.20.0030.0309.10
5.2.10.0060.0269.02
5.2.00.0060.0318.88
5.1.60.0040.0248.20
5.1.50.0060.0228.20
5.1.40.0050.0248.18
5.1.30.0060.0268.52
5.1.20.0020.0298.54
5.1.10.0050.0258.27
5.1.00.0060.0238.27
5.0.50.0070.0166.77
5.0.40.0010.0216.63
5.0.30.0030.0316.44
5.0.20.0030.0236.43
5.0.10.0010.0226.40
5.0.00.0030.0356.39
4.4.90.0030.0154.80
4.4.80.0040.0134.78
4.4.70.0040.0144.78
4.4.60.0010.0174.78
4.4.50.0040.0144.80
4.4.40.0040.0274.78
4.4.30.0020.0164.78
4.4.20.0010.0184.84
4.4.10.0050.0144.85
4.4.00.0060.0234.82
4.3.110.0030.0154.71
4.3.100.0080.0194.70
4.3.90.0010.0164.70
4.3.80.0020.0254.68
4.3.70.0020.0164.69
4.3.60.0030.0144.70
4.3.50.0040.0154.69
4.3.40.0040.0244.65
4.3.30.0020.0163.46
4.3.20.0030.0203.44
4.3.10.0040.0323.39
4.3.00.0070.01715.69

preferences:
27.65 ms | 401 KiB | 5 Q