3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Data coming from MySQL Database $rowData = []; $rowData[] = ['id' => 74, 'name' => 'First Store', 'categories' => 'Food']; $rowData[] = ['id' => 74, 'name' => 'First Store', 'categories' => 'DVDs']; $rowData[] = ['id' => 1, 'name' => 'Second Store', 'categories' => 'Food']; $rowData[] = ['id' => 1, 'name' => 'Second Store', 'categories' => 'Toys']; $rowData[] = ['id' => 1, 'name' => 'Second Store', 'categories' => 'Toys']; $rowData[] = ['id' => 1, 'name' => 'Second Store', 'categories' => 'Clothing']; $rowData[] = ['id' => 3, 'name' => 'Third Store', 'categories' => 'Toys']; $rowData[] = ['id' => 3, 'name' => 'Third Store', 'categories' => 'Clothing']; $rowData[] = ['id' => 3, 'name' => 'Third Store', 'categories' => 'Clothing']; /** * Check if store category name already added to store record */ function categoryExistsAlready($categories, $category) { foreach($categories as $key => $catArr) { if(strtolower($catArr['name']) === strtolower($category)) { return true; } } return false; } $storeTracker = []; foreach($rowData as $key => $storeData) { $storeCategory = $storeData['categories']; $storeId = $storeData['id']; // If store exists, add category to categories array if (array_key_exists($storeId, $storeTracker)) { if (!categoryExistsAlready($storeTracker[$storeId]['categories'], $storeCategory)) { $storeTracker[$storeId]['categories'][] = ['name' => $storeCategory]; } continue; } // Update store categories to be array with category $storeData['categories'] = []; $storeData['categories'][] = ['name' => $storeCategory]; // Add store data to overall tracking array $storeTracker[$storeId] = $storeData; } // Format JSON response $jsonReturn = '['; $i = count($storeTracker); foreach($storeTracker as $storeId => $storeData) { $i--; $jsonReturn .= json_encode($storeData); // Determine last comma separating objects if ($i > 0) { $jsonReturn .= ','; } } $jsonReturn .= ']'; echo $jsonReturn;

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.5.10.0120.00616.54
8.5.00.0140.00920.18
8.4.150.0020.00014.05
8.4.140.0120.00917.79
8.4.130.0140.00717.66
8.4.120.0100.00923.96
8.4.110.0070.00422.29
8.4.100.0150.00618.82
8.4.90.0040.00518.97
8.4.80.0040.00518.75
8.4.70.0110.00917.81
8.4.60.0150.00419.15
8.4.50.0070.00218.77
8.4.40.0080.00019.42
8.4.30.0030.01020.57
8.4.20.0100.01020.50
8.4.10.0100.01019.48
8.3.280.0160.00718.47
8.3.270.0150.00516.82
8.3.260.0110.00616.87
8.3.250.0090.01118.77
8.3.240.0120.00717.05
8.3.230.0070.00216.55
8.3.220.0130.00518.86
8.3.210.0130.00616.46
8.3.200.0060.00316.66
8.3.190.0130.00517.21
8.3.180.0110.00717.30
8.3.170.0070.01120.65
8.3.160.0040.01417.19
8.3.150.0140.00717.36
8.3.140.0040.00417.11
8.3.130.0090.00018.44
8.3.120.0130.00620.60
8.3.110.0000.00816.79
8.3.100.0090.00016.73
8.3.90.0050.00326.77
8.3.80.0030.00716.75
8.3.70.0140.00416.58
8.3.60.0120.00618.43
8.3.50.0090.00917.56
8.3.40.0070.00718.57
8.3.30.0150.00418.69
8.3.20.0040.00421.77
8.3.10.0080.00019.10
8.3.00.0070.00021.73
8.2.290.0120.00720.46
8.2.280.0050.00318.69
8.2.270.0040.00417.41
8.2.260.0130.00316.81
8.2.250.0110.00016.41
8.2.240.0090.00618.72
8.2.230.0060.00320.94
8.2.220.0040.00424.06
8.2.210.0040.00426.77
8.2.200.0070.00318.41
8.2.190.0150.00016.58
8.2.180.0040.01125.92
8.2.170.0110.00418.71
8.2.160.0060.00620.52
8.2.150.0060.00624.18
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0040.00426.16
8.2.110.0070.00320.53
8.2.100.0040.00817.91
8.2.90.0030.00617.63
8.2.80.0040.00417.97
8.2.70.0030.00617.93
8.2.60.0080.00018.22
8.2.50.0060.00318.16
8.2.40.0080.00019.47
8.2.30.0070.00019.33
8.2.20.0080.00018.02
8.2.10.0000.00718.95
8.2.00.0000.00719.45
8.1.330.0140.00521.95
8.1.320.0130.00916.40
8.1.310.0070.01018.42
8.1.300.0050.00318.23
8.1.290.0040.00430.84
8.1.280.0040.01125.92
8.1.270.0040.00422.14
8.1.260.0040.00426.35
8.1.250.0000.00828.09
8.1.240.0060.00323.84
8.1.230.0030.00919.15
8.1.220.0040.00417.77
8.1.210.0060.00318.77
8.1.200.0090.00017.48
8.1.190.0080.00017.10
8.1.180.0040.00418.10
8.1.170.0050.00318.57
8.1.160.0040.00418.98
8.1.150.0020.00518.91
8.1.140.0000.00818.91
8.1.130.0030.00320.14
8.1.120.0000.00817.42
8.1.110.0040.00417.46
8.1.100.0000.00717.40
8.1.90.0000.00817.45
8.1.80.0000.00717.46
8.1.70.0080.00017.48
8.1.60.0040.00717.64
8.1.50.0020.00517.57
8.1.40.0080.00017.52
8.1.30.0000.00817.72
8.1.20.0000.00817.68
8.1.10.0060.00317.64
8.1.00.0000.00817.58
8.0.300.0000.00919.62
8.0.290.0000.00716.75
8.0.280.0040.00418.38
8.0.270.0050.00316.77
8.0.260.0030.00320.29
8.0.250.0000.00717.00
8.0.240.0000.00717.00
8.0.230.0070.00016.96
8.0.220.0030.00316.96
8.0.210.0040.00416.84
8.0.200.0040.00416.93
8.0.190.0000.00817.02
8.0.180.0030.00316.91
8.0.170.0030.00816.83
8.0.160.0000.01016.84
8.0.150.0040.00416.86
8.0.140.0060.00416.91
8.0.130.0060.00013.28
8.0.120.0050.00316.79
8.0.110.0030.00516.88
8.0.100.0000.00716.85
8.0.90.0040.00416.92
8.0.80.0100.01016.87
8.0.70.0050.00316.98
8.0.60.0020.00516.96
8.0.50.0000.00816.99
8.0.30.0120.01217.25
8.0.20.0100.01716.84
8.0.10.0040.00416.85
8.0.00.0090.00816.86
7.4.330.0000.00515.55
7.4.320.0000.00816.62
7.4.300.0030.00316.64
7.4.290.0000.00716.54
7.4.280.0040.00416.38
7.4.270.0070.00016.48
7.4.260.0030.00516.68
7.4.250.0080.00016.50
7.4.240.0000.00716.62
7.4.230.0040.00316.73
7.4.220.0070.00016.52
7.4.210.0080.00816.61
7.4.200.0030.00316.62
7.4.140.0120.00617.86
7.4.130.0070.01016.67
7.4.120.0060.01116.59
7.4.110.0100.01216.48
7.4.100.0110.00816.49
7.4.90.0060.01216.52
7.4.80.0090.00919.39
7.4.70.0120.00616.63
7.4.60.0110.00516.47
7.4.50.0040.01516.46
7.4.40.0030.01316.66
7.4.00.0060.00915.18
7.3.330.0000.00613.39
7.3.320.0050.00013.35
7.3.310.0030.00316.30
7.3.300.0000.00716.41
7.3.290.0000.00716.27
7.3.280.0020.01216.35
7.3.260.0080.00916.50
7.3.240.0080.00816.52
7.3.230.0120.00816.40
7.3.210.0000.01616.48
7.3.200.0150.00416.30
7.3.190.0130.00316.60
7.3.180.0100.00716.56
7.3.170.0080.01516.73
7.3.160.0030.01316.27
7.3.50.0180.00314.70
7.3.40.0070.00714.88
7.3.30.0060.01514.86
7.3.20.0120.01214.84
7.3.10.0100.01014.64
7.3.00.0120.00314.70
7.2.330.0100.00816.68
7.2.320.0060.01216.84
7.2.310.0060.01016.48
7.2.300.0070.01016.41
7.2.290.0030.01416.73
7.2.180.0080.00414.82
7.2.170.0000.01315.12
7.2.160.0090.00314.62
7.2.150.0030.01015.23
7.2.140.0250.01015.02
7.2.130.0030.01214.97
7.2.120.0100.00614.82
7.2.110.0030.01015.17
7.2.100.0030.01015.06
7.2.90.0360.00614.80
7.2.80.0120.01015.10
7.2.70.0200.00315.00
7.2.60.0110.00315.04
7.2.50.0030.01015.22
7.2.40.0100.00314.94
7.2.30.0140.01114.94
7.2.20.0180.00015.18
7.2.10.0040.01115.25
7.2.00.0150.01115.13
7.1.280.0200.00313.89
7.1.270.0520.01014.03
7.1.260.0140.00413.84
7.1.250.0110.00313.78

preferences:
172.52 ms | 403 KiB | 5 Q