3v4l.org

run code in 300+ PHP versions simultaneously
<?php function is_cyclic(array &$array) { $lastKey = array_key_last($array); if ($lastKey === null) { // Array is empty return false; } static $marker; if ($marker === null) { $marker = new stdClass(); } if ($array[$lastKey] === $marker) { return true; } $array[] = $marker; foreach ($array as &$item) { if (is_array($item) && is_cyclic($item)) { array_pop($array); return true; } } array_pop($array); return false; } // Contains reference to itself $v = [1, 2, 3]; $v[1] = &$v; // Contains nested array with reference to $x $x = [1, [2, 3]]; $x[1][1] = &$x; // Contains nested array with reference to an ancestor $y = [1, [2, [3, 4]]]; $y[1][1][1] = &$y[1]; // Nested array contains reference to itself $z = [1, [2, 3]]; $z[1][1] = &$z[1]; // This array is not recursive $p = [1, 2, [3, 4, [5, 6, 7]]]; foreach (['v', 'x', 'y', 'z', 'p'] as $var) { $arr = &${$var}; echo "Array \$$var | Cyclic: "; var_export(is_cyclic($arr)); echo "\n"; echo "----------------\n"; var_dump($arr); echo "\n\n"; }

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.140.0030.00517.10
8.3.130.0160.00618.50
8.3.120.0060.00320.84
8.3.110.0060.00316.64
8.3.100.0060.00316.63
8.3.90.0040.00426.77
8.3.80.0030.00619.36
8.3.70.0040.01216.58
8.3.60.0110.00718.28
8.3.50.0110.00824.50
8.3.40.0060.00918.85
8.3.30.0030.01218.84
8.3.20.0050.00324.18
8.3.10.0040.00424.66
8.3.00.0000.00826.16
8.2.250.0100.01018.48
8.2.240.0090.00017.02
8.2.230.0100.01020.94
8.2.220.0030.00524.06
8.2.210.0120.00626.77
8.2.200.0000.01118.88
8.2.190.0040.01116.58
8.2.180.0110.00425.92
8.2.170.0060.01018.96
8.2.160.0150.00322.96
8.2.150.0040.00425.66
8.2.140.0040.01124.66
8.2.130.0080.00026.16
8.2.120.0080.00021.02
8.2.110.0070.00322.24
8.2.100.0110.00017.97
8.2.90.0040.00420.46
8.2.80.0040.00420.51
8.2.70.0000.00817.63
8.2.60.0000.00818.16
8.2.50.0100.00718.07
8.2.40.0080.00018.34
8.2.30.0000.00718.27
8.2.20.0080.00018.13
8.2.10.0090.00019.22
8.2.00.0040.00419.19
8.1.300.0130.00316.32
8.1.290.0060.00330.84
8.1.280.0070.00725.92
8.1.270.0050.00323.99
8.1.260.0060.00326.35
8.1.250.0000.00828.09
8.1.240.0070.00319.21
8.1.230.0040.00821.01
8.1.220.0040.00417.77
8.1.210.0040.00418.97
8.1.200.0060.00317.35
8.1.190.0050.00317.22
8.1.180.0060.00318.10
8.1.170.0040.00418.64
8.1.160.0040.00418.91
8.1.150.0000.00818.87
8.1.140.0040.00418.89
8.1.130.0000.00717.45
8.1.120.0080.00017.47
8.1.110.0000.00917.46
8.1.100.0000.00917.35
8.1.90.0040.00417.36
8.1.80.0030.00517.48
8.1.70.0080.00017.46
8.1.60.0040.00417.59
8.1.50.0050.00317.59
8.1.40.0000.00817.41
8.1.30.0040.00417.65
8.1.20.0060.00317.71
8.1.10.0040.00417.50
8.1.00.0040.00417.44
8.0.300.0000.00720.05
8.0.290.0070.00016.75
8.0.280.0000.00718.50
8.0.270.0070.00018.08
8.0.260.0000.00716.88
8.0.250.0060.00317.03
8.0.240.0070.00016.89
8.0.230.0060.00317.00
8.0.220.0050.00316.97
8.0.210.0040.00416.93
8.0.200.0050.00316.89
8.0.190.0030.00617.06
8.0.180.0050.00216.90
8.0.170.0030.00616.96
8.0.160.0070.00016.88
8.0.150.0030.00516.91
8.0.140.0050.00316.86
8.0.130.0000.00613.38
8.0.120.0050.00216.84
8.0.110.0000.00716.94
8.0.100.0040.00417.02
8.0.90.0000.00716.79
8.0.80.0120.00616.93
8.0.70.0050.00316.83
8.0.60.0000.00816.99
8.0.50.0080.00016.76
8.0.30.0120.00617.25
8.0.20.0140.00416.97
8.0.10.0090.00917.09
8.0.00.0060.01916.88
7.4.330.0050.00015.55
7.4.320.0040.00416.52
7.4.300.0030.00316.51
7.4.290.0050.00316.45
7.4.280.0000.00716.57
7.4.270.0030.00616.52
7.4.260.0050.00013.39
7.4.250.0030.00316.46
7.4.240.0000.00716.46
7.4.230.0050.00216.59
7.4.220.0040.00416.32
7.4.210.0030.01016.41
7.4.200.0000.00816.61
7.4.140.0130.00615.93
7.4.130.0120.01216.58
7.4.120.0150.00916.38
7.4.110.0130.01316.43
7.4.100.0070.01016.39
7.4.90.0150.00615.67
7.4.80.0170.00715.78
7.4.70.0070.01315.76
7.4.60.0090.00915.91
7.4.50.0110.01015.92
7.4.40.0250.00016.22
7.4.30.0060.01416.18
7.4.20.0120.00616.05
7.4.10.0160.00616.29
7.4.00.0030.01516.60
7.3.330.0040.00416.33
7.3.320.0000.00613.46
7.3.310.0050.00316.28
7.3.300.0030.00316.39
7.3.290.0040.01016.37
7.3.260.0100.00716.63
7.3.250.0110.01516.34
7.3.240.0150.00916.74
7.3.230.0070.01116.45
7.3.220.0140.00715.89
7.3.210.0090.01616.00
7.3.200.0190.00415.78
7.3.190.0000.02016.25
7.3.180.0100.01016.02
7.3.170.0240.00315.79
7.3.160.0170.00616.11
7.3.150.0120.00916.11
7.3.140.0190.00415.96
7.3.130.0150.00616.11
7.3.120.0180.00315.97
7.3.110.0190.00416.03
7.3.100.0070.01316.05
7.3.90.0140.00816.14
7.3.80.0170.00316.00
7.3.70.0120.00816.14
7.3.60.0080.01116.26
7.3.50.0080.01516.28
7.3.40.0190.00516.25
7.3.30.0130.00816.14
7.3.20.0150.00416.06
7.3.10.0150.00716.04
7.3.00.0150.01216.18

preferences:
38.51 ms | 403 KiB | 5 Q