3v4l.org

run code in 300+ PHP versions simultaneously
<?php //You must validate your input to make sure the string you pass is not empty and is, in fact, a string. An empty string is not valid JSON. function is_json($string) { return !empty($string) && is_string($string) && is_array(json_decode($string, true)) && json_last_error() == 0; } //I think in PHP it's more important to determine if the JSON object even has data, because to use the data you will need to call json_encode() //or json_decode(). I suggest denying empty JSON objects so you aren't unnecessarily running encodes and decodes on empty data. function has_json_data($string) { $array = json_decode($string, true); return !empty($string) && is_string($string) && is_array($array) && !empty($array) && json_last_error() == 0; } function isJson($string, $assoc = false) { var_dump(json_decode($string)); json_decode($string, $assoc); if(!empty($string) && is_string($string)) { json_decode($string, $assoc); return (json_last_error() == JSON_ERROR_NONE); // return json_decode($str) != null; } return false; } /** * Checks whether a string is valid json. * * @param string $string * @return boolean */ function json_is($string) { try { // try to decode string json_decode($string); } catch (ErrorException $e) { // exception has been caught which means argument wasn't a string and thus is definitely no json. return FALSE; } // check if error occured return (json_last_error() == JSON_ERROR_NONE); } $a=['arraiii'=>['dentro'=>234]]; $b=json_encode($a); $c='{ "book": [ { "id":"01", "language": "Java", "edition": "third", "author": "Herbert Schildt" }, { "id":"07", "language": "C++", "edition": "second" "author": "E.Balagurusamy" }] }'; var_dump(json_is($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.0120.00318.32
8.3.50.0140.00521.21
8.3.40.0040.01119.02
8.3.30.0100.00320.17
8.3.20.0050.00320.46
8.3.10.0040.00422.04
8.3.00.0000.00722.39
8.2.180.0040.01518.29
8.2.170.0070.00722.96
8.2.160.0100.00322.11
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0000.00720.75
8.2.110.0050.00522.09
8.2.100.0000.01217.84
8.2.90.0000.00819.09
8.2.80.0030.00519.32
8.2.70.0030.00717.50
8.2.60.0080.00017.93
8.2.50.0040.00418.07
8.2.40.0030.00618.16
8.2.30.0070.00019.46
8.2.20.0000.00817.57
8.2.10.0000.00717.65
8.2.00.0030.00517.86
8.1.280.0160.00025.92
8.1.270.0040.00423.99
8.1.260.0050.00326.35
8.1.250.0030.00528.09
8.1.240.0070.00323.72
8.1.230.0040.00719.01
8.1.220.0000.00817.74
8.1.210.0060.00318.77
8.1.200.0030.00717.23
8.1.190.0000.00817.55
8.1.180.0040.00418.10
8.1.170.0040.00418.46
8.1.160.0040.00418.81
8.1.150.0080.00018.50
8.1.140.0070.00017.41
8.1.130.0000.00717.83
8.1.120.0040.00417.43
8.1.110.0000.00717.42
8.1.100.0000.00817.38
8.1.90.0040.00317.35
8.1.80.0050.00317.46
8.1.70.0080.00017.36
8.1.60.0040.00417.55
8.1.50.0030.00617.44
8.1.40.0060.00317.54
8.1.30.0000.00717.66
8.1.20.0040.00417.55
8.1.10.0040.00417.63
8.1.00.0100.00017.50
8.0.300.0070.00018.77
8.0.290.0040.00417.05
8.0.280.0030.00318.31
8.0.270.0000.00717.20
8.0.260.0050.00316.84
8.0.250.0040.00416.87
8.0.240.0000.00816.94
8.0.230.0070.00016.90
8.0.220.0000.00716.89
8.0.210.0070.00016.95
8.0.200.0040.00416.96
8.0.190.0040.00416.96
8.0.180.0060.00616.82
8.0.170.0040.00416.95
8.0.160.0030.00516.81
8.0.150.0030.00516.71
8.0.140.0030.00316.90
8.0.130.0050.00013.28
8.0.120.0040.00416.75
8.0.110.0070.00016.79
8.0.100.0050.00216.72
8.0.90.0030.00616.93
8.0.80.0060.00916.88
8.0.70.0040.00416.80
8.0.60.0000.00716.82
8.0.50.0040.00416.96
8.0.30.0110.00817.09
8.0.20.0120.00617.40
8.0.10.0000.00716.89
8.0.00.0090.01216.80
7.4.330.0060.00015.00
7.4.320.0060.00316.50
7.4.300.0030.00316.63
7.4.290.0030.00316.63
7.4.280.0000.00616.56
7.4.270.0030.00316.64
7.4.260.0030.00313.28
7.4.250.0040.00416.48
7.4.240.0030.00416.55
7.4.230.0070.00016.59
7.4.220.0100.00916.50
7.4.210.0090.00616.47
7.4.200.0000.00716.61
7.4.190.0000.00716.64
7.4.160.0040.01816.39
7.4.150.0030.01617.40
7.4.140.0090.00817.86
7.4.130.0070.00916.52
7.4.120.0080.00916.67
7.4.110.0150.00716.59
7.4.100.0100.00716.45
7.4.90.0130.00716.65
7.4.80.0130.00319.39
7.4.70.0170.00016.26
7.4.60.0150.00316.41
7.4.50.0040.00016.33
7.4.40.0070.00722.77
7.4.30.0030.01416.43
7.4.00.0070.00814.90
7.3.330.0000.00613.38
7.3.320.0050.00013.32
7.3.310.0040.00416.34
7.3.300.0000.00616.26
7.3.290.0110.00716.30
7.3.280.0070.00916.24
7.3.270.0030.01417.40
7.3.260.0040.01316.65
7.3.250.0080.01116.45
7.3.240.0070.01016.57
7.3.230.0100.00716.39
7.3.210.0000.01716.49
7.3.200.0070.01019.39
7.3.190.0090.01216.51
7.3.180.0080.01316.46
7.3.170.0120.00816.49
7.3.160.0140.00316.32
7.3.120.0030.01214.90
7.3.110.0030.01215.02
7.3.100.0100.00314.61
7.3.90.0000.00914.84
7.3.80.0060.01014.54
7.3.70.0090.00314.63
7.3.60.0070.01014.93
7.3.50.0060.00614.68
7.3.40.0060.00914.73
7.3.30.0060.00914.91
7.3.20.0000.01516.70
7.3.10.0070.00716.31
7.3.00.0060.00616.58
7.2.330.0110.00616.64
7.2.320.0160.00216.38
7.2.310.0100.00716.75
7.2.300.0060.01016.63
7.2.290.0100.01016.61
7.2.250.0120.00315.00
7.2.240.0040.01414.73
7.2.230.0000.01014.89
7.2.220.0000.01215.20
7.2.210.0040.01214.98
7.2.200.0140.00314.75
7.2.190.0040.00814.78
7.2.180.0090.00614.98
7.2.170.0040.00815.04
7.2.00.0030.01019.25
7.1.330.0030.01315.93
7.1.320.0070.00715.96
7.1.310.0060.00615.62
7.1.300.0000.01215.81
7.1.290.0100.00315.64
7.1.280.0000.01215.55
7.1.270.0040.00415.63
7.1.260.0000.01515.46
7.1.100.0100.00518.09
7.1.70.0060.01217.21
7.1.60.0100.01319.32
7.1.50.0040.01516.91
7.1.00.0030.03322.34
7.0.200.0100.00316.76
7.0.140.0100.06722.10
7.0.90.0470.05719.98
7.0.80.0230.06719.99
7.0.70.0270.04719.88
7.0.60.0630.08019.95
7.0.50.0330.07720.37
7.0.40.0030.05020.15
7.0.30.0100.07720.07
7.0.20.0070.06020.13
7.0.10.0100.08320.10
7.0.00.0030.07720.13
5.6.280.0030.07720.90
5.6.240.0100.04020.65
5.6.230.0070.08320.50
5.6.220.0030.08320.52
5.6.210.0200.05720.62
5.6.200.0100.07021.07
5.6.190.0030.08321.09
5.6.180.0200.06321.03
5.6.170.0100.07721.03
5.6.160.0230.07321.11
5.6.150.0100.08021.04
5.6.140.0070.04021.07
5.6.130.0070.08721.11
5.6.120.0170.06021.11
5.6.110.0100.05320.97
5.6.100.0100.07021.05
5.6.90.0100.08020.95
5.6.80.0030.06020.47
5.6.70.0230.06320.40
5.6.60.0030.05020.33
5.6.50.0070.08020.42
5.6.40.0100.06720.30
5.6.30.0130.06720.48
5.6.20.0070.05320.38
5.6.10.0030.06720.45
5.6.00.0070.07320.29
5.5.380.0100.07320.50
5.5.370.0200.06320.52
5.5.360.0170.06020.36
5.5.350.0000.04720.38
5.5.340.0170.07720.77
5.5.330.0070.04320.79
5.5.320.0000.09020.90
5.5.310.0070.07320.89
5.5.300.0070.06720.74
5.5.290.0130.03320.81
5.5.280.0100.04320.81
5.5.270.0030.06020.73
5.5.260.0070.08020.86
5.5.250.0000.09020.55
5.5.240.0200.06320.24
5.5.230.0030.08320.18
5.5.220.0130.04720.02
5.5.210.0170.06320.27
5.5.200.0030.07020.23
5.5.190.0100.04320.14
5.5.180.0130.07020.27
5.5.160.0100.05020.13
5.5.150.0070.05720.19
5.5.140.0070.04320.22
5.5.130.0030.07720.13
5.5.120.0100.07320.00
5.5.110.0070.04020.13
5.5.100.0200.06720.02
5.5.90.0070.08020.12
5.5.80.0030.06720.05
5.5.70.0070.07320.02
5.5.60.0070.05019.97
5.5.50.0130.06320.11
5.5.40.0030.06720.07
5.5.30.0070.07320.06
5.5.20.0100.07720.09
5.5.10.0030.07720.05
5.5.00.0070.07720.03
5.4.450.0100.04719.56
5.4.440.0070.08019.38
5.4.430.0170.03719.22
5.4.420.0030.04319.35
5.4.410.0100.07719.22
5.4.400.0070.06719.13
5.4.390.0030.04719.04
5.4.380.0070.07018.84
5.4.370.0070.04319.20
5.4.360.0170.06318.88
5.4.350.0100.07318.95
5.4.340.0000.05719.04
5.4.320.0170.06719.21
5.4.310.0030.04319.08
5.4.300.0030.05019.04
5.4.290.0170.06719.20
5.4.280.0030.05719.14
5.4.270.0030.05719.13
5.4.260.0070.07719.21
5.4.250.0200.06319.02
5.4.240.0030.08019.04
5.4.230.0070.07319.12
5.4.220.0100.07719.09
5.4.210.0070.05019.13
5.4.200.0130.05319.03
5.4.190.0070.07018.86
5.4.180.0100.06319.23
5.4.170.0000.06319.12
5.4.160.0070.06318.86
5.4.150.0100.04319.21
5.4.140.0100.06316.44
5.4.130.0030.04716.34
5.4.120.0030.04316.43
5.4.110.0070.06016.53
5.4.100.0100.03016.54
5.4.90.0000.04016.55
5.4.80.0070.06316.38
5.4.70.0070.06716.43
5.4.60.0030.05016.30
5.4.50.0000.04716.47
5.4.40.0130.05016.44
5.4.30.0130.06316.48
5.4.20.0100.07016.30
5.4.10.0070.07016.26
5.4.00.0200.06015.81
5.3.290.0100.03714.80
5.3.280.0070.07714.73
5.3.270.0030.08714.61
5.3.260.0070.06714.64
5.3.250.0100.07314.59
5.3.240.0030.04714.56
5.3.230.0030.08314.58
5.3.220.0070.05014.72
5.3.210.0000.05014.50
5.3.200.0070.04014.71
5.3.190.0000.04014.56
5.3.180.0100.06714.64
5.3.170.0070.05014.71
5.3.160.0100.07314.67
5.3.150.0030.04714.69
5.3.140.0000.07314.69
5.3.130.0070.07014.61
5.3.120.0000.04314.59
5.3.110.0070.07314.55
5.3.100.0070.04014.06
5.3.90.0130.06714.01
5.3.80.0070.07314.05
5.3.70.0030.07714.16
5.3.60.0100.04014.12
5.3.50.0030.04714.02
5.3.40.0130.06713.88
5.3.30.0000.08013.97
5.3.20.0030.07013.84
5.3.10.0030.04713.76
5.3.00.0070.03313.55
5.2.170.0030.06711.27
5.2.160.0070.04711.07
5.2.150.0100.05311.18
5.2.140.0000.07011.18
5.2.130.0070.06311.03
5.2.120.0070.03711.13
5.2.110.0030.05011.13
5.2.100.0030.03311.24
5.2.90.0000.04711.17
5.2.80.0030.04011.13
5.2.70.0070.06011.12
5.2.60.0130.04711.16
5.2.50.0070.05711.03
5.2.40.0100.03311.14
5.2.30.0070.06311.07
5.2.20.0030.04011.06
5.2.10.0170.05010.80
5.2.00.0030.06310.85
5.1.60.0030.05010.00
5.1.50.0030.0579.86
5.1.40.0030.05710.10
5.1.30.0130.05010.46
5.1.20.0030.05710.23
5.1.10.0070.03310.16
5.1.00.0130.0479.93
5.0.50.0070.0438.61
5.0.40.0130.0238.46
5.0.30.0100.0678.35
5.0.20.0000.0378.30
5.0.10.0030.0238.17
5.0.00.0030.0608.26
4.4.90.0030.0307.78
4.4.80.0000.0377.78
4.4.70.0030.0337.78
4.4.60.0070.0307.78
4.4.50.0030.0377.78
4.4.40.0000.0577.78
4.4.30.0000.0307.78
4.4.20.0070.0307.78
4.4.10.0030.0377.78
4.4.00.0030.0507.78
4.3.110.0030.0307.78
4.3.100.0000.0377.78
4.3.90.0030.0307.78
4.3.80.0030.0277.78
4.3.70.0000.0377.78
4.3.60.0030.0237.78
4.3.50.0030.0377.78
4.3.40.0000.0437.78
4.3.30.0000.0177.78
4.3.20.0000.0177.78
4.3.10.0030.0137.78
4.3.00.0030.0207.78

preferences:
54.5 ms | 401 KiB | 5 Q