3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array ( 0 => array ( 'r_id' => 11, 'r_sid' => 'RC', 'd_id' => 2 ), 1 => array ( 'r_id' => 7, 'r_sid' => 'RC', 'c_id' => 51 ), 2 => array ( 'r_id' => 6, 'r_sid' => 'JN', 'c_id' => 52 ), 3 => array ( 'r_id' => 7, 'r_sid' => 'JN', 'c_id' => 51 ), 4 => array ( 'r_id' => 7, 'r_sid' => 'LG', 'c_id' => 51 ), 5 => array ( 'r_id' => 7, 'r_sid' => 'BN', 'c_id' => 51 ), 6 => array ( 'r_id' => 6, 'r_sid' => 'IVS', 'c_id' => 52 ), 7 => array ( 'r_id' => 7, 'r_sid' => 'IVS', 'c_id' => 51 ) ); // filter out r_sid values which only occur once $sid_values = array_count_values(array_column($array, 'r_sid')); $array = array_filter($array, function ($a) use ($sid_values) { return $sid_values[$a['r_sid']] > 1; }); // combine arrays on r_sid values $result = array(); foreach ($array as $arr) { $sid = $arr['r_sid']; // push data to arrays $result[$sid]['r_sid'] = $sid; $result[$sid]['r_id'][] = $arr['r_id']; if (isset($arr['c_id'])) $result[$sid]['c_id'][] = $arr['c_id']; if (isset($arr['d_id'])) $result[$sid]['d_id'][] = $arr['d_id']; } // combine all the c_id values into a string array_walk($result, function (&$a) { if (isset($a['c_id'])) $a['c_id'] = implode(',', $a['c_id']); }); // now combine any r_sid values that have the same set of c_id values $output = array(); foreach ($result as $res) { $cid = $res['c_id']; // push data to arrays $output[$cid]['c_id'] = $cid; $output[$cid]['r_sid'] = array_merge($output[$cid]['r_sid'] ?? array(), array($res['r_sid'])); $output[$cid]['r_id'] = array_merge($output[$cid]['r_id'] ?? array(), $res['r_id']); if (isset($res['d_id'])) $output[$cid]['d_id'] = array_merge($output[$cid]['d_id'] ?? array(), $res['d_id']); } // combine the r_sid, r_id and d_id values into a string array_walk($output, function (&$a) { $a['r_sid'] = implode(',', $a['r_sid']); $a['r_id'] = implode(',', array_unique($a['r_id'])); if (isset($a['d_id'])) $a['d_id'] = implode(',', $a['d_id']); }); // remove the associative keys $output = array_values($output); print_r($output);

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.130.0040.00618.85
8.4.120.0100.01124.02
8.4.110.0130.00720.52
8.4.100.0070.01418.81
8.4.90.0130.00722.42
8.4.80.0130.00819.45
8.4.70.0110.01017.88
8.4.60.0040.00418.68
8.4.50.0090.01217.71
8.4.40.0100.01017.65
8.4.30.0120.00818.88
8.4.20.0100.01017.79
8.4.10.0060.00319.64
8.3.260.0110.00816.64
8.3.250.0110.00919.18
8.3.240.0140.00717.29
8.3.230.0050.00316.46
8.3.220.0030.00517.10
8.3.210.0050.00316.52
8.3.200.0050.00416.71
8.3.190.0040.00416.77
8.3.180.0060.00416.81
8.3.170.0110.00016.77
8.3.160.0090.00918.61
8.3.150.0060.01217.34
8.3.140.0100.00720.74
8.3.130.0100.00016.79
8.3.120.0100.00620.71
8.3.110.0030.00720.94
8.3.100.0170.00316.85
8.3.90.0030.00620.29
8.3.80.0080.00418.55
8.3.70.0120.00616.63
8.3.60.0120.00318.31
8.3.50.0100.00624.45
8.3.40.0150.00018.80
8.3.30.0100.01018.68
8.3.20.0070.00021.98
8.3.10.0040.00422.09
8.3.00.0000.00821.73
8.2.290.0140.00520.27
8.2.280.0110.00722.05
8.2.270.0110.00716.44
8.2.260.0150.00016.71
8.2.250.0030.01216.85
8.2.240.0040.00417.44
8.2.230.0000.01022.58
8.2.220.0060.00624.06
8.2.210.0100.00326.77
8.2.200.0030.01016.63
8.2.190.0060.01616.63
8.2.180.0070.00718.30
8.2.170.0110.00422.96
8.2.160.0110.00322.27
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0050.00226.16
8.2.110.0030.00722.25
8.2.100.0080.00417.78
8.2.90.0030.00518.03
8.2.80.0030.00517.97
8.2.70.0050.00317.63
8.2.60.0090.00018.02
8.2.50.0040.00418.05
8.2.40.0050.00318.22
8.2.30.0040.00419.39
8.2.20.0000.00818.22
8.2.10.0040.00419.22
8.2.00.0040.00419.22
8.1.330.0100.00922.15
8.1.320.0130.00416.50
8.1.310.0090.00617.91
8.1.300.0000.00820.15
8.1.290.0030.00618.88
8.1.280.0080.00625.92
8.1.270.0090.00020.42
8.1.260.0060.00326.35
8.1.250.0040.00428.09
8.1.240.0100.00022.55
8.1.230.0090.00322.72
8.1.220.0000.00817.79
8.1.210.0000.00818.77
8.1.200.0030.00617.35
8.1.190.0040.00417.23
8.1.180.0060.00318.10
8.1.170.0040.00417.62
8.1.160.0000.00718.96
8.1.150.0040.00418.83
8.1.140.0040.00418.84
8.1.130.0080.00020.13
8.1.120.0000.00717.46
8.1.110.0040.00417.34
8.1.100.0070.00017.50
8.1.90.0040.00417.54
8.1.80.0000.00817.47
8.1.70.0000.00817.46
8.1.60.0060.00317.62
8.1.50.0030.00517.57
8.1.40.0080.00017.57
8.1.30.0000.00717.56
8.1.20.0040.00417.74
8.1.10.0070.00017.54
8.1.00.0030.00617.50
8.0.300.0040.00419.98
8.0.290.0000.00816.63
8.0.280.0070.00018.60
8.0.270.0070.00018.05
8.0.260.0000.00718.35
8.0.250.0060.00317.00
8.0.240.0030.00317.00
8.0.230.0040.00416.97
8.0.220.0000.00716.93
8.0.210.0030.00316.96
8.0.200.0000.00616.98
8.0.190.0030.00616.88
8.0.180.0030.00516.89
8.0.170.0030.00616.90
8.0.160.0050.00316.96
8.0.150.0070.00016.94
8.0.140.0000.00716.93
8.0.130.0050.00013.36
8.0.120.0030.00516.80
8.0.110.0000.00816.79
8.0.100.0000.00816.97
8.0.90.0040.00416.91
8.0.80.0110.00916.92
8.0.70.0050.00317.04
8.0.60.0040.00416.71
8.0.50.0040.00416.75
8.0.30.0100.00717.06
8.0.20.0040.01717.42
8.0.10.0000.00717.14
8.0.00.0140.00816.79
7.4.330.0040.00015.55
7.4.320.0030.00316.55
7.4.300.0000.00616.49
7.4.290.0040.00416.63
7.4.280.0050.00316.51
7.4.270.0070.00016.55
7.4.260.0080.00016.62
7.4.250.0030.00316.58
7.4.240.0020.00716.62
7.4.230.0000.00816.38
7.4.220.0030.00316.74
7.4.210.0070.00816.63
7.4.200.0000.00716.61
7.4.130.0050.01316.51
7.4.120.0090.00916.52
7.4.110.0110.00616.43
7.4.100.0130.00316.54
7.4.90.0040.01516.37
7.4.80.0140.00619.39
7.4.70.0110.01116.41
7.4.60.0070.01016.40
7.4.50.0090.00916.43
7.4.40.0090.00916.25
7.4.30.0090.00916.44
7.4.20.0160.00616.43
7.4.10.0130.00916.36
7.4.00.0090.00916.77
7.3.330.0080.00016.24
7.3.320.0000.00513.36
7.3.310.0080.00016.30
7.3.300.0000.00716.33
7.3.290.0130.00116.43
7.3.280.0030.01216.41
7.3.260.0120.00616.46
7.3.240.0130.00616.55
7.3.230.0140.00316.36
7.3.210.0100.00716.27
7.3.200.0060.01316.62
7.3.190.0060.01016.68
7.3.180.0090.00916.64
7.3.170.0120.01216.34
7.3.160.0080.01216.52
7.3.150.0060.01216.34
7.3.140.0210.00316.45
7.3.130.0100.01216.35
7.3.120.0120.01216.34
7.3.110.0120.00616.58
7.3.100.0090.01216.40
7.3.90.0070.01516.22
7.3.80.0130.01016.44
7.3.70.0190.00916.27
7.3.60.0060.01516.49
7.3.50.0100.01016.33
7.3.40.0090.00916.27
7.3.30.0190.00616.32
7.3.20.0080.01116.50
7.3.10.0060.01216.31
7.3.00.0140.00916.18
7.2.330.0060.01216.66
7.2.320.0140.00416.74
7.2.310.0090.00616.72
7.2.300.0070.01316.86
7.2.290.0100.01016.61
7.2.280.0120.01216.81
7.2.270.0060.01216.48
7.2.260.0110.00716.48
7.2.250.0100.01316.77
7.2.240.0090.01616.89
7.2.230.0070.01616.68
7.2.220.0030.02316.49
7.2.210.0090.01716.36
7.2.200.0060.01716.89
7.2.190.0170.00016.80
7.2.180.0070.01116.61
7.2.170.0100.01016.61
7.2.160.0070.01716.42
7.2.150.0130.00816.44
7.2.140.0090.01316.58
7.2.130.0090.01816.40
7.2.120.0110.01416.57
7.2.110.0160.00316.45
7.2.100.0100.01016.71
7.2.90.0180.01116.60
7.2.80.0160.00616.76
7.2.70.0000.02216.66
7.2.60.1130.00616.70
7.2.50.0100.01016.66
7.2.40.0040.01816.78
7.2.30.0030.02016.36
7.2.20.0110.01116.58
7.2.10.0090.00916.61
7.2.00.0040.01816.55

preferences:
126.65 ms | 403 KiB | 5 Q