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; } $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(isJson($b));

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.0180.00318.31
8.3.50.0160.00221.27
8.3.40.0060.00918.53
8.3.30.0040.00920.31
8.3.20.0080.00020.29
8.3.10.0060.00321.92
8.3.00.0040.00422.32
8.2.180.0100.01016.63
8.2.170.0140.00422.96
8.2.160.0070.00722.11
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0070.00026.16
8.2.120.0040.00420.70
8.2.110.0100.00020.39
8.2.100.0040.00817.72
8.2.90.0030.00519.17
8.2.80.0040.00417.97
8.2.70.0040.00417.63
8.2.60.0070.00017.93
8.2.50.0080.00018.07
8.2.40.0060.00318.22
8.2.30.0000.00719.48
8.2.20.0050.00317.75
8.2.10.0050.00317.83
8.2.00.0030.00517.77
8.1.280.0070.01025.92
8.1.270.0040.00423.99
8.1.260.0070.00026.35
8.1.250.0040.00428.09
8.1.240.0070.00423.89
8.1.230.0040.00817.45
8.1.220.0000.00817.79
8.1.210.0040.00418.77
8.1.200.0060.00317.35
8.1.190.0000.00817.52
8.1.180.0000.00818.10
8.1.170.0000.00818.50
8.1.160.0070.00020.67
8.1.150.0000.00818.53
8.1.140.0000.00717.39
8.1.130.0000.00717.79
8.1.120.0000.00817.50
8.1.110.0040.00417.43
8.1.100.0030.00517.51
8.1.90.0000.00717.48
8.1.80.0070.00017.36
8.1.70.0000.00717.41
8.1.60.0000.00817.59
8.1.50.0040.00417.45
8.1.40.0030.00617.51
8.1.30.0020.00517.48
8.1.20.0050.00317.66
8.1.10.0040.00417.50
8.1.00.0110.00017.42
8.0.300.0070.00018.77
8.0.290.0000.01016.63
8.0.280.0040.00418.38
8.0.270.0030.00317.30
8.0.260.0030.00316.84
8.0.250.0000.00716.86
8.0.240.0000.00816.86
8.0.230.0070.00017.02
8.0.220.0040.00416.98
8.0.210.0070.00016.87
8.0.200.0000.00717.02
8.0.190.0040.00417.02
8.0.180.0070.00316.80
8.0.170.0000.00816.91
8.0.160.0050.00216.79
8.0.150.0030.00716.85
8.0.140.0000.00716.78
8.0.130.0050.00013.30
8.0.120.0000.00816.88
8.0.110.0040.00416.83
8.0.100.0040.00416.79
8.0.90.0040.00416.71
8.0.80.0090.00616.87
8.0.70.0080.00016.86
8.0.60.0030.00616.82
8.0.50.0080.00016.86
8.0.30.0090.01117.04
8.0.20.0090.01117.40
8.0.10.0000.00816.95
8.0.00.0120.00916.76
7.4.330.0020.00215.00
7.4.320.0000.00716.66
7.4.300.0030.00316.55
7.4.290.0070.00016.55
7.4.280.0030.00316.52
7.4.270.0000.00716.59
7.4.260.0050.00013.30
7.4.250.0040.00416.39
7.4.240.0000.00716.50
7.4.230.0030.00316.28
7.4.220.0110.00716.66
7.4.210.0060.00816.54
7.4.200.0030.00316.65
7.4.190.0040.00416.43
7.4.160.0140.00316.47
7.4.150.0110.01117.40
7.4.140.0130.01017.86
7.4.130.0090.00816.63
7.4.120.0070.01316.52
7.4.110.0070.01016.36
7.4.100.0130.00616.58
7.4.90.0100.01016.55
7.4.80.0030.01419.39
7.4.70.0080.00816.37
7.4.60.0140.00316.42
7.4.50.0000.00416.47
7.4.40.0060.01022.77
7.4.30.0110.00716.52
7.4.00.0050.01014.85
7.3.330.0000.00513.27
7.3.320.0030.00313.12
7.3.310.0070.00016.12
7.3.300.0030.00316.27
7.3.290.0100.00916.26
7.3.280.0110.00716.25
7.3.270.0150.00317.40
7.3.260.0150.00316.19
7.3.250.0070.01216.48
7.3.240.0120.00616.36
7.3.230.0090.00816.55
7.3.210.0150.00716.46
7.3.200.0030.01419.39
7.3.190.0120.00916.32
7.3.180.0090.00916.61
7.3.170.0000.01516.49
7.3.160.0100.00716.36
7.3.120.0080.00814.87
7.3.110.0070.00714.92
7.3.100.0030.01314.62
7.3.90.0070.00714.63
7.3.80.0100.00315.11
7.3.70.0080.00314.76
7.3.60.0070.01014.69
7.3.50.0070.00414.97
7.3.40.0100.00314.66
7.3.30.0000.01614.55
7.3.20.0030.00616.65
7.3.10.0130.00016.68
7.3.00.0000.01216.82
7.2.330.0070.01416.67
7.2.320.0080.01116.43
7.2.310.0150.00916.79
7.2.300.0090.00916.66
7.2.290.0130.00916.55
7.2.250.0000.01715.02
7.2.240.0100.01014.96
7.2.230.0070.01015.04
7.2.220.0030.00615.22
7.2.210.0070.00715.08
7.2.200.0040.00815.02
7.2.190.0100.00615.01
7.2.180.0030.01015.11
7.2.170.0060.01114.92
7.2.60.0080.00016.94
7.1.330.0070.00715.67
7.1.320.0040.00815.84
7.1.310.0050.00315.85
7.1.300.0030.00915.76
7.1.290.0060.00615.83
7.1.280.0090.00615.80
7.1.270.0120.00315.80
7.1.260.0070.00715.79
7.1.200.0120.00015.52
7.1.70.0040.00417.13
7.1.60.0120.00819.32
7.1.50.0070.01516.87
7.1.00.0030.05322.37
7.0.200.0000.00716.95
7.0.140.0030.07722.15
7.0.90.0400.04319.98
7.0.80.0330.05719.93
7.0.70.0370.04020.01
7.0.60.0430.04719.96
7.0.50.0600.08020.32
7.0.40.0100.04320.18
7.0.30.0230.06320.10
7.0.20.0100.08320.04
7.0.10.0170.05720.08
7.0.00.0130.07020.07
5.6.280.0000.07720.87
5.6.240.0030.05320.73
5.6.230.0100.06320.66
5.6.220.0100.05020.50
5.6.210.0030.05020.77
5.6.200.0070.07721.14
5.6.190.0030.07721.12
5.6.180.0030.08021.03
5.6.170.0100.07320.91
5.6.160.0100.06021.05
5.6.150.0070.08021.06
5.6.140.0030.05320.96
5.6.130.0200.07320.94
5.6.120.0070.04721.05
5.6.110.0200.07320.99
5.6.100.0070.08021.13
5.6.90.0000.08721.06
5.6.80.0100.07720.46
5.6.70.0200.07020.47
5.6.60.0100.04320.49
5.6.50.0130.06720.53
5.6.40.0170.07020.38
5.6.30.0130.06320.30
5.6.20.0030.08720.41
5.6.10.0130.07320.42
5.6.00.0170.07320.52
5.5.380.0100.05020.38
5.5.370.0130.03320.45
5.5.360.0170.05720.39
5.5.350.0030.04320.48
5.5.340.0070.08020.89
5.5.330.0130.07020.81
5.5.320.0100.07720.84
5.5.310.0130.07320.79
5.5.300.0070.04020.77
5.5.290.0130.07720.90
5.5.280.0100.06720.94
5.5.270.0130.08020.74
5.5.260.0100.07020.73
5.5.250.0070.06720.74
5.5.240.0030.08020.29
5.5.230.0130.07720.25
5.5.220.0070.03720.11
5.5.210.0030.08720.29
5.5.200.0070.05720.17
5.5.190.0100.07320.19
5.5.180.0130.07320.16
5.5.160.0200.06320.13
5.5.150.0170.07020.18
5.5.140.0100.07720.22
5.5.130.0070.07720.09
5.5.120.0070.07020.27
5.5.110.0100.05020.17
5.5.100.0100.05019.98
5.5.90.0030.05720.16
5.5.80.0100.03720.09
5.5.70.0100.07320.13
5.5.60.0130.07020.16
5.5.50.0030.08320.09
5.5.40.0030.08320.06
5.5.30.0200.06720.15
5.5.20.0100.07720.16
5.5.10.0000.08020.02
5.5.00.0130.07320.07
5.4.450.0030.08019.18
5.4.440.0030.07319.42
5.4.430.0070.06719.21
5.4.420.0100.08019.55
5.4.410.0100.07019.40
5.4.400.0130.06718.90
5.4.390.0070.08018.93
5.4.380.0070.07719.03
5.4.370.0070.06319.11
5.4.360.0070.08019.14
5.4.350.0070.07319.23
5.4.340.0100.07719.18
5.4.320.0130.07019.14
5.4.310.0000.08719.13
5.4.300.0070.07319.02
5.4.290.0070.07018.93
5.4.280.0100.07319.12
5.4.270.0100.07319.20
5.4.260.0100.07019.02
5.4.250.0070.07718.83
5.4.240.0070.07319.20
5.4.230.0070.04719.18
5.4.220.0130.07319.03
5.4.210.0100.07719.03
5.4.200.0130.07319.02
5.4.190.0100.07718.86
5.4.180.0100.07319.03
5.4.170.0070.07319.13
5.4.160.0030.05019.16
5.4.150.0100.06719.12
5.4.140.0070.04716.20
5.4.130.0170.06316.49
5.4.120.0070.07016.41
5.4.110.0100.07016.39
5.4.100.0130.06016.37
5.4.90.0070.06316.57
5.4.80.0100.06316.55
5.4.70.0070.04016.47
5.4.60.0070.07316.45
5.4.50.0100.07016.45
5.4.40.0070.06316.53
5.4.30.0030.07716.39
5.4.20.0000.05016.41
5.4.10.0130.04316.30
5.4.00.0030.07315.85
5.3.290.0130.06714.64
5.3.280.0000.05014.56
5.3.270.0070.05314.62
5.3.260.0070.04314.66
5.3.250.0100.06314.60
5.3.240.0070.05314.60
5.3.230.0000.06714.59
5.3.220.0100.07714.60
5.3.210.0000.07314.61
5.3.200.0070.07714.52
5.3.190.0170.07014.63
5.3.180.0170.05714.63
5.3.170.0100.07314.68
5.3.160.0000.04714.52
5.3.150.0100.03714.54
5.3.140.0070.07714.62
5.3.130.0130.07314.56
5.3.120.0070.05714.56
5.3.110.0100.06714.59
5.3.100.0070.04014.11
5.3.90.0030.07014.15
5.3.80.0100.03313.96
5.3.70.0100.04013.93
5.3.60.0130.06313.93
5.3.50.0000.06714.06
5.3.40.0070.07014.02
5.3.30.0030.06013.97
5.3.20.0030.08013.82
5.3.10.0100.05713.57
5.3.00.0130.07013.63
5.2.170.0070.05711.20
5.2.160.0030.06011.29
5.2.150.0070.06011.20
5.2.140.0070.05711.07
5.2.130.0070.06311.04
5.2.120.0030.05711.02
5.2.110.0100.06010.99
5.2.100.0070.06311.16
5.2.90.0030.05711.17
5.2.80.0100.05311.09
5.2.70.0000.07011.13
5.2.60.0000.06011.06
5.2.50.0070.05710.85
5.2.40.0070.05710.96
5.2.30.0030.06011.07
5.2.20.0000.04710.90
5.2.10.0000.03710.93
5.2.00.0070.06010.66
5.1.60.0000.0339.84
5.1.50.0000.04010.00
5.1.40.0030.04010.08
5.1.30.0070.05310.38
5.1.20.0030.05710.43
5.1.10.0100.03710.17
5.1.00.0030.05710.16
5.0.50.0130.0378.66
5.0.40.0070.0408.43
5.0.30.0100.0508.30
5.0.20.0000.0438.30
5.0.10.0070.0378.25
5.0.00.0100.0478.23
4.4.90.0000.0407.51
4.4.80.0030.0377.51
4.4.70.0000.0237.51
4.4.60.0030.0337.51
4.4.50.0030.0407.51
4.4.40.0070.0477.51
4.4.30.0030.0377.51
4.4.20.0000.0277.51
4.4.10.0030.0307.51
4.4.00.0000.0577.51
4.3.110.0030.0377.51
4.3.100.0070.0337.51
4.3.90.0030.0337.51
4.3.80.0030.0377.51
4.3.70.0100.0277.51
4.3.60.0100.0237.51
4.3.50.0030.0337.51
4.3.40.0000.0537.51
4.3.30.0030.0337.51
4.3.20.0030.0337.51
4.3.10.0000.0377.51
4.3.00.0000.0377.51

preferences:
66.89 ms | 401 KiB | 5 Q