3v4l.org

run code in 300+ PHP versions simultaneously
<?php function buildPedigree($haystack, $akc_reg_num, $generation = 0) { ++$generation; foreach ($haystack as $index => $row) { if ($row['akc_reg_num'] == $akc_reg_num) { $result = ['sire' => $row['akc_parent_sire'], 'dam' => $row['akc_parent_dam']]; unset($haystack[$index]); // reduce the haystack to improve efficiency and avoid infinite loop break; } } if (!isset($result)) { return []; // $akc_reg_num not found } foreach ($haystack as $row) { if ($row['akc_reg_num'] == $result['sire']) { $result['sire_parents'] = array_filter(buildPedigree($haystack, $row['akc_reg_num'], $generation)); // recurse and purge empty parent arrays if (array_key_exists('dam_parents', $result)) { break; // both parents found in generation, stop this loop } } elseif ($row['akc_reg_num'] == $result['dam']) { $result['dam_parents'] = array_filter(buildPedigree($haystack, $row['akc_reg_num'], $generation)); // recurse and purge empty parent arrays if (array_key_exists('sire_parents', $result)) { break; // both parents found in generation, stop this loop } } } return $generation <= 4 ? $result : []; } $animals = [ ['id' => 1, 'akc_reg_num' => 1, 'akc_parent_sire' => 2, 'akc_parent_dam' => 3], ['id' => 2, 'akc_reg_num' => 2, 'akc_parent_sire' => 5, 'akc_parent_dam' => 6], ['id' => 3, 'akc_reg_num' => 3, 'akc_parent_sire' => 9, 'akc_parent_dam' => 0], ['id' => 4, 'akc_reg_num' => 5, 'akc_parent_sire' => 0, 'akc_parent_dam' => 0], ['id' => 5, 'akc_reg_num' => 6, 'akc_parent_sire' => 7, 'akc_parent_dam' => 8], ['id' => 6, 'akc_reg_num' => 7, 'akc_parent_sire' => 0, 'akc_parent_dam' => 0], ['id' => 7, 'akc_reg_num' => 8, 'akc_parent_sire' => 0, 'akc_parent_dam' => 0], ['id' => 8, 'akc_reg_num' => 9, 'akc_parent_sire' => 10, 'akc_parent_dam' => 11], ['id' => 9, 'akc_reg_num' => 10, 'akc_parent_sire' => 0, 'akc_parent_dam' => 0], ['id' => 10, 'akc_reg_num' => 11, 'akc_parent_sire' => 12, 'akc_parent_dam' => 0], ['id' => 11, 'akc_reg_num' => 12, 'akc_parent_sire' => 0, 'akc_parent_dam' => 0] ]; var_export(buildPedigree($animals, 1));

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.4.120.0080.01017.84
8.4.110.0150.00518.58
8.4.100.0040.00517.95
8.4.90.0120.00918.80
8.4.80.0120.00817.72
8.4.70.0090.00717.71
8.4.60.0120.00818.58
8.4.50.0110.00818.75
8.4.40.0070.00417.72
8.4.30.0080.01219.44
8.4.20.0030.00618.89
8.4.10.0040.00419.48
8.3.250.0120.00618.99
8.3.240.0070.00217.19
8.3.230.0090.01116.63
8.3.220.0050.00417.36
8.3.210.0110.00818.30
8.3.200.0080.00816.62
8.3.190.0100.00516.73
8.3.180.0100.00816.59
8.3.170.0130.00619.12
8.3.160.0110.00718.46
8.3.150.0120.00618.96
8.3.140.0040.00419.12
8.3.130.0040.00418.85
8.3.120.0030.00620.77
8.3.110.0060.00320.94
8.3.100.0120.00424.06
8.3.90.0090.00026.77
8.3.80.0000.00918.55
8.3.70.0270.00916.66
8.3.60.0300.00317.50
8.3.50.0130.00317.34
8.3.40.0230.00818.07
8.3.30.0200.00618.03
8.3.20.0100.00419.05
8.3.10.0140.00119.54
8.3.00.0120.00619.95
8.2.290.0100.00220.39
8.2.280.0120.00716.42
8.2.270.0080.00019.19
8.2.260.0090.00616.58
8.2.250.0030.00318.64
8.2.240.0060.00918.75
8.2.230.0030.00622.58
8.2.220.0000.00837.54
8.2.210.0140.00026.77
8.2.200.0040.00718.38
8.2.190.0180.00716.75
8.2.180.0250.00316.73
8.2.170.0180.00720.36
8.2.160.0180.00619.32
8.2.150.0110.00920.84
8.2.140.0170.00521.02
8.2.130.0210.00017.88
8.2.120.0220.00521.86
8.2.110.0260.00319.28
8.2.100.0260.00217.61
8.2.90.0140.00317.80
8.2.80.0170.00517.72
8.2.70.0140.00617.56
8.2.60.0180.00217.76
8.2.50.0170.00917.66
8.2.40.0160.00418.18
8.2.30.0150.00318.10
8.2.20.0100.00318.18
8.2.10.0150.00318.00
8.2.00.0100.00517.65
8.1.330.0060.00322.26
8.1.320.0140.00815.93
8.1.310.0040.01118.31
8.1.300.0040.00416.73
8.1.290.0080.00430.84
8.1.280.0150.01021.25
8.1.270.0150.00518.72
8.1.260.0130.00221.86
8.1.250.0140.00622.72
8.1.240.0110.00520.67
8.1.230.0130.00619.14
8.1.220.0180.00617.46
8.1.210.0180.00817.76
8.1.200.0230.00617.17
8.1.190.0170.00717.11
8.1.180.0190.00717.53
8.1.170.0170.00717.59
8.1.160.0170.00717.69
8.1.150.0120.00417.63
8.1.140.0100.00718.87
8.1.130.0140.00418.09
8.1.120.0120.00417.33
8.1.110.0090.00817.35
8.1.100.0140.00317.80
8.1.90.0160.00417.35
8.1.80.0160.00517.35
8.1.70.0160.00817.29
8.1.60.0190.00417.40
8.1.50.0150.00317.35
8.1.40.0100.00717.40
8.1.30.0120.00517.62
8.1.20.0120.00417.52
8.1.10.0130.00717.38
8.1.00.0150.00517.27
8.0.300.0210.00217.66
8.0.290.0180.00616.65
8.0.280.0170.00817.19
8.0.270.0150.00416.90
8.0.260.0160.00317.18
8.0.250.0100.00616.74
8.0.240.0110.00516.77
8.0.230.0100.00616.78
8.0.220.0120.00416.71
8.0.210.0140.00216.74
8.0.200.0100.00516.77
8.0.190.0090.00616.79
8.0.180.0110.00616.77
8.0.170.0150.00416.75
8.0.160.0140.00416.78
8.0.150.0110.00916.74
8.0.140.0130.00616.72
8.0.130.0120.00515.81
8.0.120.0100.00516.67
8.0.110.0120.00416.71
8.0.100.0140.00316.72
8.0.90.0180.00416.69
8.0.80.0120.00916.79
8.0.70.0150.00516.75
8.0.60.0130.00816.75
8.0.50.0130.00716.79
8.0.30.0140.00716.89
8.0.20.0140.00716.92
8.0.10.0170.00716.94
8.0.00.0120.00916.87
7.4.330.0140.00516.52
7.4.320.0190.00316.52
7.4.300.0190.00316.56
7.4.290.0190.00316.57
7.4.280.0170.00416.55
7.4.270.0170.00616.57
7.4.260.0170.00516.58
7.4.250.0160.00516.52
7.4.240.0080.00916.56
7.4.230.0160.00216.62
7.4.220.0160.00316.53
7.4.210.0100.00916.55
7.4.200.0150.00516.52
7.4.190.0110.00916.59
7.4.180.0120.00816.59
7.4.160.0130.00616.52
7.4.150.0150.00616.58
7.4.140.0150.00516.82
7.4.130.0180.00516.55
7.4.120.0140.00716.54
7.4.110.0120.00816.56
7.4.100.0180.00616.52
7.4.90.0160.00516.48
7.4.80.0150.00816.87
7.4.70.0150.00616.51
7.4.60.0140.00516.52
7.4.50.0120.00616.47
7.4.40.0160.00416.48
7.4.30.0120.00716.50
7.4.20.0150.00416.46
7.4.10.0140.00616.47
7.4.00.0110.00616.31
7.3.330.0130.00315.75
7.3.320.0130.00315.67
7.3.310.0090.00716.49
7.3.300.0110.00516.43
7.3.290.0110.00616.40
7.3.280.0150.00716.42
7.3.270.0130.00816.45
7.3.260.0130.00716.44
7.3.250.0120.01116.43
7.3.240.0130.00716.44
7.3.230.0130.00916.42
7.3.220.0170.00516.39
7.3.210.0140.00916.42
7.3.200.0130.00916.42
7.3.190.0130.00816.39
7.3.180.0150.00516.42
7.3.170.0140.00916.44
7.3.160.0150.00716.42
7.3.150.0140.00716.37
7.3.140.0140.00816.40
7.3.130.0140.00816.41
7.3.120.0140.00616.43
7.3.110.0150.00416.35
7.3.100.0110.00615.79
7.3.90.0110.00715.96
7.3.80.0090.01015.81
7.3.70.0100.00815.85
7.3.60.0110.00815.82
7.3.50.0130.00615.80
7.3.40.0110.00915.71
7.3.30.0140.00615.70
7.3.20.0190.00916.16
7.3.10.0190.00916.15
7.3.00.0210.00816.16
7.2.340.0170.01016.47
7.2.330.0150.00816.49
7.2.320.0170.00716.51
7.2.310.0140.00816.54
7.2.300.0150.00816.52
7.2.290.0140.00816.50
7.2.280.0160.00716.47
7.2.270.0140.00816.45
7.2.260.0150.00716.48
7.2.250.0140.00716.45
7.2.240.0160.00716.50
7.2.230.0120.00815.93
7.2.220.0140.00515.92
7.2.210.0130.00715.90
7.2.200.0140.00716.08
7.2.190.0130.00815.93
7.2.180.0140.00715.97
7.2.170.0130.00815.93
7.2.160.0140.00915.89
7.2.150.0230.00716.39
7.2.140.0270.00916.46
7.2.130.0210.00716.48
7.2.120.0200.00816.42
7.2.110.0200.00816.48
7.2.100.0210.00816.45
7.2.90.0230.00416.43
7.2.80.0210.00816.48
7.2.70.0200.00716.45
7.2.60.0200.00716.47
7.2.50.0180.00916.39
7.2.40.0200.00816.50
7.2.30.0360.00516.46
7.2.20.0150.00816.45
7.2.10.0200.00816.52
7.2.00.0200.00816.51
7.1.330.0140.00816.55
7.1.320.0130.00715.58
7.1.310.0140.00715.61
7.1.300.0160.00615.42
7.1.290.0140.00715.45
7.1.280.0120.00815.45
7.1.270.0240.00715.33
7.1.260.0220.00715.14
7.1.250.0200.00615.15
7.1.240.0160.00916.19
7.1.230.0170.00816.16
7.1.220.0170.00816.24
7.1.210.0190.00716.22
7.1.200.0190.01016.24
7.1.190.0170.00916.22
7.1.180.0170.01016.22
7.1.170.0210.00616.15
7.1.160.0200.00616.18
7.1.150.0170.00816.16
7.1.140.0160.00816.21
7.1.130.0200.00816.20
7.1.120.0180.00716.26
7.1.110.0180.00816.20
7.1.100.0180.00716.13
7.1.90.0170.00716.20
7.1.80.0160.00816.25
7.1.70.0140.00816.12
7.1.60.0170.00716.27
7.1.50.0190.00716.27
7.1.40.0140.00916.23
7.1.30.0170.00616.22
7.1.20.0150.00916.20
7.1.10.0160.00716.20
7.1.00.0190.00616.18

preferences:
32.27 ms | 403 KiB | 5 Q