3v4l.org

run code in 500+ PHP versions simultaneously
<?php $products = [ [ 'item_number' => 15678, 'description' => 'Tophat', 'size' => 'small', 'shelf' => 5, 'aisle' => 12, 'quantity' => 10, 'price' => 5.99 ], [ 'item_number' => 15644, 'description' => 'Something Else', 'size' => 'Large', 'shelf' => 6, 'aisle' => 10, 'quantity' => 99, 'price' => 8.99 ], [ 'item_number' => 15662, 'description' => 'T-shirt', 'size' => 'large', 'shelf' => 9, 'aisle' => 13, 'quantity' => 15, 'price' => null ] ]; function is_valid($product): bool { foreach ($product as $value) { if (!is_int($value) && !is_string($value) && !is_float($value)) { return false; } } return true; } function create_inventory(array $products): array { $inventory = []; // loop over your product array using the index to create an array if the product is valid. foreach ($products as $index => $product) { if (is_valid($product)) { // Create an empty array when the product is valid. $inventory[$index] = []; // Loop over the product values and add them to the newly created array. foreach ($product as $key => $value) { $inventory[$index][$key] = $value; } } } return $inventory; } var_dump(create_inventory($products));

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.70.0080.00816.85
8.5.60.0100.00716.99
8.5.50.0140.00516.72
8.5.30.0090.00819.99
8.5.20.0130.00620.26
8.5.10.0050.00220.36
8.5.00.0110.01019.84
8.4.210.0070.00219.74
8.4.180.0120.01219.75
8.4.170.0130.00823.75
8.4.160.0120.01222.04
8.4.150.0070.00516.88
8.4.140.0140.00817.89
8.4.130.0130.00718.87
8.4.120.0100.00918.02
8.4.110.0100.01123.89
8.4.100.0130.00817.85
8.4.90.0130.00820.44
8.4.80.0050.00319.00
8.4.70.0050.00319.06
8.4.60.0110.00920.71
8.4.50.0070.00718.55
8.4.40.0160.00319.41
8.4.30.0100.00320.33
8.4.20.0110.00019.57
8.4.10.0090.01217.93
8.3.300.0160.00918.66
8.3.290.0110.01020.99
8.3.280.0120.00918.49
8.3.270.0150.00416.57
8.3.260.0130.00716.61
8.3.250.0090.00816.81
8.3.240.0140.00616.53
8.3.230.0030.00616.79
8.3.220.0120.00819.21
8.3.210.0110.00518.27
8.3.200.0060.00216.68
8.3.190.0150.00417.00
8.3.180.0100.00719.14
8.3.170.0100.01017.14
8.3.160.0100.01017.33
8.3.150.0100.01016.65
8.3.140.0050.00316.57
8.3.130.0070.00018.28
8.3.120.0000.00818.86
8.3.110.0000.00820.94
8.3.100.0040.00424.06
8.3.90.0080.00026.77
8.3.80.0090.00016.75
8.3.70.0100.01016.88
8.3.60.0070.00718.43
8.3.50.0090.00619.95
8.3.40.0060.00919.30
8.3.30.0070.00719.07
8.3.20.0080.00024.18
8.3.10.0040.00424.66
8.3.00.0000.00826.16
8.2.300.0110.01220.36
8.2.290.0100.00116.57
8.2.280.0110.00718.36
8.2.270.0100.00716.71
8.2.260.0080.00016.85
8.2.250.0030.00618.24
8.2.240.0030.00617.43
8.2.230.0000.00822.58
8.2.220.0040.00437.54
8.2.210.0040.00426.77
8.2.200.0040.00416.50
8.2.190.0160.00616.75
8.2.180.0070.01125.92
8.2.170.0140.00718.99
8.2.160.0100.00722.96
8.2.150.0040.00425.66
8.2.140.0000.00824.66
8.2.130.0080.00026.16
8.2.120.0060.00326.16
8.2.110.0100.00020.95
8.2.100.0040.00817.84
8.2.90.0050.00319.22
8.2.80.0000.00818.03
8.2.70.0000.00817.63
8.2.60.0050.00518.04
8.2.50.0040.00418.07
8.2.40.0000.00818.09
8.2.30.0050.00318.17
8.2.20.0040.00420.59
8.2.10.0000.00717.77
8.2.00.0030.00519.41
8.1.340.0100.00920.15
8.1.330.0070.01216.25
8.1.320.0100.01116.05
8.1.310.0090.00616.79
8.1.300.0080.00016.13
8.1.290.0070.00318.88
8.1.280.0130.00625.92
8.1.270.0050.00323.99
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0000.00922.02
8.1.230.0070.00422.21
8.1.220.0030.00517.78
8.1.210.0030.00618.77
8.1.200.0080.00317.35
8.1.190.0030.00517.35
8.1.180.0050.00318.10
8.1.170.0000.00818.58
8.1.160.0040.00418.89
8.1.150.0020.00518.68
8.1.140.0030.00617.49
8.1.130.0000.00718.84
8.1.120.0050.00217.55
8.1.110.0040.00417.50
8.1.100.0040.00417.40
8.1.90.0050.00217.52
8.1.80.0000.00717.50
8.1.70.0060.00317.57
8.1.60.0050.00317.68
8.1.50.0050.00317.43
8.1.40.0080.00017.58
8.1.30.0200.00617.55
8.1.20.0230.00317.64
8.1.10.0190.00817.52
8.1.00.0160.01217.55
8.0.300.0070.00318.77
8.0.290.0030.00616.75
8.0.280.0040.00418.40
8.0.270.0040.00417.97
8.0.260.0030.00318.45
8.0.250.0000.00817.01
8.0.240.0030.00316.98
8.0.230.0030.00317.05
8.0.220.0040.00416.91
8.0.210.0030.00616.92
8.0.200.0040.00416.88
8.0.190.0030.00517.00
8.0.180.0030.00516.96
8.0.170.0080.00016.84
8.0.160.0220.00016.97
8.0.150.0150.00616.85
8.0.140.0160.00316.88
8.0.130.0180.00316.93
8.0.120.0170.00416.93
8.0.110.0130.00616.94
8.0.100.0170.00416.73
8.0.90.0100.01116.95
8.0.80.0140.00716.94
8.0.70.0120.01116.94
8.0.60.0200.00016.87
8.0.50.0200.00016.92
8.0.30.0150.00416.82
8.0.20.0110.01117.01
8.0.10.0150.00517.07
7.4.330.0000.00615.55
7.4.320.0070.00016.63
7.4.300.0000.00716.59
7.4.290.0000.00816.46
7.4.280.0200.00016.63
7.4.270.0170.00316.39
7.4.260.0120.00616.57
7.4.250.0080.01216.45
7.4.240.0200.00316.63
7.4.230.0200.00016.64
7.4.220.0070.01116.44
7.4.210.0160.00216.62
7.4.200.0130.00416.45
7.4.190.0170.00016.67
7.4.180.0190.00016.71
7.4.160.0100.01016.61
7.4.150.0140.00716.63
7.4.140.0130.00716.55
7.4.130.0140.00616.50
7.4.120.0130.00616.38
7.4.110.0140.00516.50
7.4.100.0150.00616.60
7.4.90.0140.00616.41
7.4.80.0140.00716.48
7.4.70.0140.00716.45
7.4.60.0150.00516.39
7.4.50.0190.00016.37
7.4.40.0090.00916.40
7.4.30.0090.00916.49
7.4.20.0120.00916.48
7.4.10.0130.00616.37
7.4.00.0080.01216.41

preferences:
53.53 ms | 1358 KiB | 5 Q