3v4l.org

run code in 300+ PHP versions simultaneously
<?php // -- PULLING IN PRODUCTS TO READ OUT TO USER -- // $stmt = (" SELECT products.ID, products.title, products.category, products.location, products.price, products.negotiable, products.description, products.photo, products.user_id FROM products"); $result = $db->query($stmt); foreach ($result as $row) { $product_id = $row['ID']; $title = htmlspecialchars($row['title'], ENT_QUOTES); // User input, prevent first order XSS $category = $row['category']; // local variable for remainder, ensuring to use htmlspecialchars() for any user input that will be read out to browser } // -- INSERTING ONE PRODUCT TO MAIN PRODUCT PAGE USING PREPARED STATEMENT -- // // Incoming user input from some form // Assign input to local variables // Probably should validate data $null_value = null; // To bind null values... I'm lazy $stmt = $db->prepare(" INSERT INTO products VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param('sssssssss', $null_value, $title, $category, $location, $price, $negotiable, $description, $photo, $user_id); $stmt->execute(); // -- INSERTING MULTIPLE PRODUCTS TO MAIN PRODUCT PAGE USING PREPARED STATEMENT -- // // Incoming user input from some form $null_value = null; // To bind null values... I'm lazy // Assuming user input is from a form // Verify it is a form submission if($_SERVER['REQUEST_METHOD'] === 'POST') { foreach ($_POST['product_array'] as $product) { foreach ($product as $row) { // Validate data types // Assign to to local variables $stmt = $db->prepare(" INSERT INTO products VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param('sssssssss', $null_value, $title, $category, $location, $price, $negotiable, $description, $photo, $user_id); $stmt->execute(); } } }

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.1.20.0040.00417.66
8.1.10.0090.00017.58
8.1.00.0030.00617.58
8.0.150.0000.00816.86
8.0.140.0000.00716.74
8.0.130.0000.00613.30
8.0.120.0040.00416.84
8.0.110.0040.00417.02
8.0.100.0000.00816.92
8.0.90.0000.00716.97
8.0.80.0120.00316.80
8.0.70.0030.00516.95
8.0.60.0080.00016.96
8.0.50.0000.00916.92
8.0.30.0030.01817.23
8.0.20.0120.01016.97
8.0.10.0000.00817.05
8.0.00.0130.01016.98
7.4.270.0000.00716.52
7.4.260.0050.00013.30
7.4.250.0030.00516.38
7.4.240.0000.00716.52
7.4.230.0050.00316.55
7.4.220.0040.00316.36
7.4.210.0090.00416.56
7.4.200.0030.00516.45
7.4.130.0090.00916.49
7.4.120.0130.01016.58
7.4.110.0070.01016.53
7.4.100.0140.00416.50
7.4.90.0100.01016.12
7.4.80.0090.00916.37
7.4.70.0120.00616.42
7.4.60.0170.00316.21
7.4.50.0120.00616.16
7.4.40.0070.01116.55
7.4.30.0170.00316.42
7.4.20.0150.00316.33
7.4.10.0050.01416.32
7.4.00.0100.00716.35
7.3.330.0000.00716.20
7.3.320.0030.00313.03
7.3.310.0000.00716.21
7.3.300.0000.00716.29
7.3.290.0070.00916.29
7.3.260.0110.00716.23
7.3.230.0060.01316.20
7.3.220.0170.00016.17
7.3.210.0140.00316.48
7.3.200.0100.01016.23
7.3.190.0120.00616.28
7.3.180.0180.00316.32
7.3.170.0170.00016.35
7.3.160.0140.00716.39
7.3.150.0090.00816.29
7.3.140.0120.00616.42
7.3.130.0120.00616.12
7.3.120.0110.00616.11
7.3.110.0080.00816.38
7.3.100.0110.00516.13
7.3.90.0100.00716.19
7.3.80.0130.01016.15
7.3.70.0100.00716.37
7.3.60.0070.01016.27
7.3.50.0110.00616.38
7.3.40.0100.00716.22
7.3.30.0090.01216.16
7.3.20.0290.00316.21
7.3.10.0000.01716.09
7.3.00.0100.00716.11
7.2.330.0090.00916.51
7.2.320.0120.00616.41
7.2.310.0060.01316.37
7.2.300.0180.00016.14
7.2.290.0090.00916.24
7.2.280.0090.00916.73
7.2.270.0100.00916.31
7.2.260.0110.01116.28
7.2.250.0140.00416.28
7.2.240.0070.01016.16
7.2.230.0030.01416.34
7.2.220.0090.00916.15
7.2.210.0130.00316.28
7.2.200.0110.00716.28
7.2.190.0090.01516.09
7.2.180.0100.00716.27
7.2.170.0110.00816.20
7.2.160.0150.00916.26
7.2.150.0300.01616.14
7.2.140.0030.01616.18
7.2.130.0100.01016.26
7.2.120.0110.00716.39
7.2.110.0090.00916.17
7.2.100.0070.01116.48
7.2.90.0090.00916.38
7.2.80.0090.00916.23
7.2.70.0100.00716.44
7.2.60.0180.00016.34
7.2.50.0090.00916.36
7.2.40.0090.00916.38
7.2.30.0110.00716.50
7.2.20.0110.00716.34
7.2.10.0130.00616.43
7.2.00.0120.00616.38

preferences:
14.13 ms | 455 KiB | 5 Q