3v4l.org

run code in 300+ PHP versions simultaneously
<?php $products = array ( 0 => array ( 'product_id' => 2, 'customer_id' => 1820, 'order_id' => 'M-AAH-959', 'quantity' => 5, 'weight' => 1.3, 'cubic' => 0.00267, 'total_weight' => 6.5, 'total_cubic' => 0.00267 ), 1 => array ( 'product_id' => 3, 'customer_id' => 1820, 'order_id' => 'M-AAH-959', 'quantity' => 6, 'weight' => 1.5, 'cubic' => 0.00348, 'total_weight' => 9, 'total_cubic' => 0.00348 ), 2 => array ( 'product_id' => 8, 'customer_id' => 1820, 'order_id' => 'M-AAH-959', 'quantity' => 7, 'weight' => 1.5, 'cubic' => 0.00267, 'total_weight' => 10.5, 'total_cubic' => 0.00267 ) ); function pack_boxes($products, $box_weight) { $boxes = array(); $this_box_weight = 0; $box_number = 0; foreach ($products as $product) { // will all this product fit? if ($product['total_weight'] < $box_weight - $this_box_weight) { // yes - add this product to the box $boxes[$box_number][] = $product; $this_box_weight += $product['total_weight']; $boxes[$box_number]['box_weight'] = $this_box_weight; } else { // no - add the part that will fit to this box $num_products = floor(($box_weight - $this_box_weight) / $product['weight']); $balance = $product['quantity'] - $num_products; $product['quantity'] = $num_products; $product['total_weight'] = $num_products * $product['weight']; $boxes[$box_number][] = $product; $boxes[$box_number]['box_weight'] = $this_box_weight + $num_products * $product['weight']; // add the balance to a new box $box_number++; $product['quantity'] = $balance; $this_box_weight = $product['total_weight'] = $balance * $product['weight']; $boxes[$box_number][] = $product; $boxes[$box_number]['box_weight'] = $this_box_weight; } } return $boxes; } $boxes = pack_boxes($products, 12); print_r(array_column($boxes, 'box_weight')); print_r($boxes);

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.0130.00623.85
8.4.110.0150.00522.34
8.4.100.0150.00620.42
8.4.90.0100.00918.92
8.4.80.0120.00718.99
8.4.70.0100.01117.85
8.4.60.0060.01018.63
8.4.50.0060.00319.50
8.4.40.0040.00420.50
8.4.30.0130.00724.14
8.4.20.0160.00317.93
8.4.10.0030.00519.42
8.3.250.0100.01019.13
8.3.240.0080.00217.13
8.3.230.0090.01016.42
8.3.220.0100.00918.99
8.3.210.0080.01018.34
8.3.200.0070.00116.64
8.3.190.0030.00516.73
8.3.180.0120.00716.42
8.3.170.0060.00316.71
8.3.160.0020.00518.39
8.3.150.0070.01118.45
8.3.140.0040.00416.88
8.3.130.0030.00518.31
8.3.120.0060.00318.85
8.3.110.0110.00020.94
8.3.100.0070.01016.36
8.3.90.0030.01618.47
8.3.80.0060.00319.36
8.3.70.0110.00716.63
8.3.60.0060.01318.68
8.3.50.0080.01224.41
8.3.40.0180.00318.62
8.3.30.0110.00418.82
8.3.20.0000.00821.86
8.3.10.0050.00322.05
8.3.00.0040.00421.75
8.2.290.0100.00820.63
8.2.280.0160.00418.30
8.2.270.0120.00617.28
8.2.260.0070.01116.43
8.2.250.0040.00416.79
8.2.240.0080.00818.69
8.2.230.0000.01022.58
8.2.220.0030.00724.06
8.2.210.0070.00026.77
8.2.200.0060.00316.25
8.2.190.0070.01016.58
8.2.180.0060.00916.38
8.2.170.0000.01522.96
8.2.160.0080.00620.47
8.2.150.0000.01024.18
8.2.140.0050.00324.66
8.2.130.0000.00826.16
8.2.120.0080.00018.84
8.2.110.0070.00320.47
8.2.100.0090.00317.91
8.2.90.0060.00319.76
8.2.80.0000.00819.48
8.2.70.0100.00017.88
8.2.60.0000.00817.93
8.2.50.0040.00418.07
8.2.40.0000.00918.15
8.2.30.0060.00318.07
8.2.20.0000.00818.25
8.2.10.0000.00819.30
8.2.00.0000.00719.29
8.1.330.0110.00822.16
8.1.320.0140.00516.29
8.1.310.0060.00318.46
8.1.300.0070.01020.01
8.1.290.0090.00018.88
8.1.280.0140.00025.92
8.1.270.0030.00622.44
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0090.00022.72
8.1.230.0050.00522.75
8.1.220.0040.00417.89
8.1.210.0090.00018.98
8.1.200.0030.00617.48
8.1.190.0050.00317.36
8.1.180.0060.00318.10
8.1.170.0030.00518.89
8.1.160.0040.00418.88
8.1.150.0050.00318.88
8.1.140.0040.00420.84
8.1.130.0030.00320.16
8.1.120.0000.00717.43
8.1.110.0060.00317.43
8.1.100.0040.00317.51
8.1.90.0000.00717.52
8.1.80.0080.00017.56
8.1.70.0070.00017.53
8.1.60.0030.00517.54
8.1.50.0000.01117.61
8.1.40.0030.00617.62
8.1.30.0000.00817.72
8.1.20.0060.00317.65
8.1.10.0040.00417.58
8.1.00.0000.01117.59
8.0.300.0040.00419.90
8.0.290.0040.00416.75
8.0.280.0030.00318.52
8.0.270.0040.00418.01
8.0.260.0030.00320.14
8.0.250.0070.00016.91
8.0.240.0070.00017.04
8.0.230.0080.00017.05
8.0.220.0000.00716.89
8.0.210.0040.00416.92
8.0.200.0040.00417.02
8.0.190.0040.00416.89
8.0.180.0080.00416.96
8.0.170.0030.00616.90
8.0.160.0040.00416.85
8.0.150.0080.00016.86
8.0.140.0000.00816.98
8.0.130.0000.00613.32
8.0.120.0000.01016.95
8.0.110.0040.00416.95
8.0.100.0070.00017.07
8.0.90.0040.00417.03
8.0.80.0090.00816.93
8.0.70.0030.00516.80
8.0.60.0040.00417.01
8.0.50.0000.00717.02
8.0.30.0110.00717.25
8.0.20.0130.00717.46
8.0.10.0030.00517.14
8.0.00.0150.00316.67
7.4.330.0000.00516.72
7.4.320.0060.00016.63
7.4.300.0060.00016.55
7.4.290.0040.00416.57
7.4.280.0030.00516.56
7.4.270.0000.00716.59
7.4.260.0000.00513.32
7.4.250.0040.00416.39
7.4.240.0020.00516.66
7.4.230.0000.00716.69
7.4.220.0050.00216.72
7.4.210.0090.00816.65
7.4.200.0000.00716.77
7.4.140.0110.00817.86
7.4.130.0070.01016.71
7.4.120.0120.00616.42
7.4.110.0070.01116.67
7.4.100.0100.00716.52
7.4.90.0060.01316.57
7.4.80.0030.01519.39
7.4.70.0130.00916.55
7.4.60.0080.01116.55
7.4.50.0070.00716.29
7.4.40.0060.01016.60
7.4.10.0090.00614.61
7.4.00.0070.01314.70
7.3.330.0040.00416.42
7.3.320.0030.00313.45
7.3.310.0070.00016.42
7.3.300.0070.00016.44
7.3.290.0070.00916.38
7.3.280.0000.01416.38
7.3.260.0120.00616.62
7.3.240.0130.00616.52
7.3.230.0030.01416.49
7.3.210.0120.00416.50
7.3.200.0120.00916.61
7.3.190.0260.00016.57
7.3.180.0080.00816.66
7.3.170.0100.00916.42
7.3.160.0040.01216.52
7.3.130.0060.01015.00
7.3.120.0140.00514.99
7.3.110.0080.01214.88
7.3.100.0070.00714.72
7.3.90.0080.01114.43
7.3.80.0060.01014.68
7.3.70.0060.01414.83
7.3.60.0080.01114.61
7.3.50.0120.00914.55
7.3.40.0190.00014.51
7.3.30.0030.01714.51
7.3.20.0130.00814.56
7.3.10.0080.00814.99
7.3.00.0100.00514.70
7.2.330.0060.01216.67
7.2.320.0070.01016.82
7.2.310.0060.01116.86
7.2.300.0210.00316.57
7.2.290.0100.00716.54
7.2.260.0030.01414.87
7.2.250.0060.01215.19
7.2.240.0090.00915.16
7.2.230.0140.00415.15
7.2.220.0170.00315.16
7.2.210.0180.00414.89
7.2.200.0090.01114.98
7.2.190.0090.01214.97
7.2.180.0070.01514.94
7.2.170.0070.01414.78
7.2.160.0090.01214.93
7.2.150.0080.01414.95
7.2.140.0110.00714.93
7.2.130.0110.00515.01
7.2.120.0080.00715.12
7.2.110.0140.00315.18
7.2.100.0080.00814.89
7.2.90.0120.00415.21
7.2.80.0070.01015.16
7.2.70.0080.00815.14
7.2.60.0050.01315.12
7.2.50.0090.00914.89
7.2.40.0140.00315.01
7.2.30.0070.01215.29
7.2.20.0060.00914.82
7.2.10.0150.00715.14
7.2.00.0100.00715.16

preferences:
27.98 ms | 403 KiB | 5 Q