3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Mock function to generate some random sales data, sometimes returning nothing. function getLocationSalesForDate(DateTime $date, string $location) { // Your business logic goes here. // Get the date as a string using DateTime::format(). // Return a random mock value for this demo. Will randomly return NULL so as to simulate // your table view. return (mt_rand(0, 3) === 1)?NULL:mt_rand(15, 70); } $locations = ['city 1', 'city 2', 'city 3', 'city 4', 'city 5', 'city 6']; $numColumns = 3; $dateStart = new DateTime; // 'P7D' means a period ('P') of 7 ('7') days ('D') from $dateStart. Consult the documentation of DateInterval's constructor for details. $dateEnd = (clone $dateStart)->add(new DateInterval('P7D')); // Segment your locations to however many you want to show on a single line. foreach (array_chunk($locations, $numColumns) as $columnHeadings) { // Output table haeding for this group of locations. $html = <<<EOT <table> <thead> <tr> <th>Date</th> EOT; // Write out each location as a column heading. foreach ($columnHeadings as $columnHeading) $html .= <<<EOT <th>$columnHeading</th> EOT; $html .= <<<EOT </tr> </thead> EOT; // Output sales per day for this location. $html .= <<<EOT <tbody> EOT; // Loop through each day between $dateStart and $dateEnd. $dateIterator = clone $dateStart; while ($dateIterator != $dateEnd) { // Start new row, print date on first column. $html .= <<<EOT <tr> <td>{$dateIterator->format('Y-m-d')}</td> EOT; // Loop through this segment's locations and fetch sales for this day. foreach ($columnHeadings as $location) { // Retrieve mock sales data for this day on this location. $sales = getLocationSalesForDate($dateIterator, $location); // Record sales if we have any. if ($sales) // Have sales. $html .= <<<EOT <td>$sales</td> EOT; else // No sales for this day. $html .= <<<EOT <td><!-- Empty cell if no sales recorded for this location on this day. --></td> EOT; } // Close sales data row. $html .= <<<EOT </tr> EOT; // Advance to next day for this location. $dateIterator->add(new DateInterval('P1D')); } // Close table for this location group. $html .= <<<EOT </tbody> </table> EOT; // Output table to user. echo $html; }

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)
7.4.120.0120.00716.73
7.4.110.0140.00516.50
7.4.100.0090.00916.87
7.4.90.0050.01316.82
7.4.80.0160.00316.63
7.4.70.0140.00616.63
7.4.60.0160.00416.47
7.4.50.0080.01216.73
7.4.40.0170.00616.68
7.4.30.0140.01016.50
7.4.20.0140.00716.59
7.4.10.0210.00316.78
7.4.00.0100.01316.61
7.3.240.0060.01216.78
7.3.230.0130.01016.57
7.3.220.0120.00716.77
7.3.210.0070.01416.60
7.3.200.0090.00916.52
7.3.190.0030.01316.62
7.3.180.0090.00916.89
7.3.170.0070.01416.55
7.3.160.0090.00916.81
7.3.150.0120.01216.73
7.3.140.0120.01716.79
7.3.130.0180.00616.71
7.3.120.0060.01016.67
7.3.110.0170.00316.84
7.3.100.0150.00816.81
7.3.90.0070.01016.89
7.3.80.0130.00516.70
7.3.70.0180.00316.74
7.3.60.0130.00616.73
7.3.50.0150.00516.63
7.3.40.0070.01416.82
7.3.30.0060.01216.84
7.3.20.0340.00916.70
7.3.10.0070.01116.73
7.3.00.0100.01016.76
7.2.340.0060.01116.84
7.2.330.0160.00616.61
7.2.320.0130.00816.41
7.2.310.0060.01516.64
7.2.300.0090.01416.60
7.2.290.0170.00616.65
7.2.280.0160.00516.91
7.2.270.0130.00716.76
7.2.260.0140.00316.99
7.2.250.0110.00716.87
7.2.240.0110.00716.87
7.2.230.0100.01316.77
7.2.220.0070.01416.94
7.2.210.0140.00416.73
7.2.200.0070.01116.75
7.2.190.0090.00916.98
7.2.180.0080.01116.74
7.2.170.0110.00716.73
7.2.160.0110.01116.84
7.2.150.0080.01217.01
7.2.140.0200.00616.95
7.2.130.0130.01016.92
7.2.120.0060.01316.96
7.2.110.0140.00916.93
7.2.100.0130.01216.97
7.2.90.0120.00616.85
7.2.80.0060.01316.87
7.2.70.0040.01816.96
7.2.60.0090.01016.95
7.2.50.0100.00716.81
7.2.40.0110.00716.91
7.2.30.0110.00716.92
7.2.20.0160.00916.91
7.2.10.0090.00916.90
7.2.00.0040.01516.81

preferences:
31.07 ms | 403 KiB | 5 Q