3v4l.org

run code in 300+ PHP versions simultaneously
<?php $table=New Table(); $table->addRecord("Jesus", "Blue", "Fish"); $table->addRecord("Tesla", "", "Coil",); echo $table->tableToHTML(); class Table { private $header; // the table's header private $data; // the actual table's data private $classesCells; // the classes of columns private $classesRows; // the classes of rows private $biggestRow; // number of cells of the longest row public function __construct() { $this->data=array(); $this->header=array(); $this->classesCells=array(); $this->classesRows=array(); $this->biggestRow=0; } /* Add/change header of table * * Takes: Variable number of strings * * */ public function makeHeader(){ $this->header=func_get_args(); // Check if biggestRow should be updated $rowLength=func_num_args(); if ($rowLength>$this->biggestRow) $this->biggestRow=$rowLength; } /* Add a record to the table * * Takes: Variable number of strings * * */ public function addRecord(){ $row=func_get_args(); $this->data[]=$row; // Check if biggestRow should be updated $rowLength=count($row); if ($rowLength>$this->biggestRow) $this->biggestRow=$rowLength; } /* Add classes to all cells on specific column * * Takes: Class name * Column number * * */ public function addClassX($classname, $x){ $rowsN=count($this->data); for ($i=0; $i<$rowsN; $i++){ $this->classesCells[$i][$x]=$classname; } } /* Add classes to every n-th row * * Takes: Class name * Every n row * Starting row position * * */ public function addClassRowEvery($classname, $n, $startingRow){ for ($i=$startingRow; $i<count($this->data); $i+=$n){ $this->classesRows[$i]=$classname; } } /* Print the table in raw format with all variables etc. * * */ public function showTableInfo() { echo '<pre>'; echo '<b>Number of cells in longest row:</b><br />'; echo $this->biggestRow . '<br />'; echo '<br /><b>Header:</b><br />'; print_r($this->header); echo '<br /><b>Data:</b><br />'; print_r($this->data); echo '<br /><b>Row classes:</b><br />'; print_r($this->classesRows); echo '<br /><b>Cell classes:</b><br />'; print_r($this->classesCells); echo '</pre>'; } /* Convert table to HTML code * * Gives: string with formatted table in HTML * * */ public function tableToHTML() { $cellsY=count($this->data); $cellsX=$this->biggestRow; $string="<table>\n"; // th case if (!empty($this->header)) { $header=$this->header; $string.="\t<tr>\n"; for ($i=0; $i<$cellsX; $i++){ $string.="\t\t<th>"; if (isset($header[$i])) $string.=$header[$i]; $string.="</th>\n"; } $string.="\t</tr>\n"; } // td case $rowNumber=0; foreach($this->data as $row){ // per row $string.="\t<tr"; // Add row classes if (!empty($this->classesRows)) { if (!empty($this->classesRows[$rowNumber])) // add row class $string.=" class='" . $this->classesRows[$rowNumber] . "'"; if ($rowNumber<($cellsY-1)) $rowNumber++; } $string.=">\n"; for ($i=0; $i<$cellsX; $i++) // per cell { $string.="\t\t<td"; // Add cell classes if (!empty($this->classesCells)) if (!empty($this->classesCells[$rowNumber][$i])) // add cell class $string.=" class='" . $this->classesCells[$rowNumber][$i] . "'"; $string.=">"; if (isset($row[$i])) $string.=$row[$i]; $string.="</td>\n"; } $string.="\t</tr>\n"; } $string.='</table>'; return $string; } /* ------------------------- SETTERS & GETTERS -------------------------------*/ /* Get length of longest row * * */ public function getXlength() { return $this->biggestRow; } }

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.3.60.0100.00718.30
8.3.50.0100.00921.15
8.3.40.0170.00318.97
8.3.30.0080.00519.22
8.3.20.0080.00020.09
8.3.10.0040.00422.13
8.3.00.0040.00422.34
8.2.180.0120.00316.75
8.2.170.0070.00722.96
8.2.160.0090.00619.18
8.2.150.0080.00024.18
8.2.140.0060.00324.66
8.2.130.0000.00826.16
8.2.120.0000.00819.23
8.2.110.0050.00521.07
8.2.100.0060.00618.34
8.2.90.0030.00519.20
8.2.80.0000.00918.05
8.2.70.0000.00817.50
8.2.60.0080.00317.93
8.2.50.0040.00418.10
8.2.40.0090.00019.88
8.2.30.0040.00418.13
8.2.20.0040.00417.64
8.2.10.0050.00217.66
8.2.00.0050.00317.77
8.1.280.0110.00425.92
8.1.270.0030.00522.20
8.1.260.0040.00426.35
8.1.250.0070.00028.09
8.1.240.0080.00019.07
8.1.230.0090.00320.13
8.1.220.0040.00417.79
8.1.210.0000.00918.77
8.1.200.0000.00917.35
8.1.190.0060.00317.35
8.1.180.0000.00918.10
8.1.170.0000.00818.50
8.1.160.0040.00422.17
8.1.150.0030.00618.73
8.1.140.0040.00417.49
8.1.130.0070.00017.87
8.1.120.0080.00017.49
8.1.110.0060.00317.47
8.1.100.0070.00017.41
8.1.90.0040.00417.56
8.1.80.0000.00817.45
8.1.70.0030.00317.42
8.1.60.0000.00817.67
8.1.50.0040.00417.55
8.1.40.0040.00417.56
8.1.30.0060.00317.56
8.1.20.0000.00817.63
8.1.10.0030.00617.63
8.1.00.0060.00317.53
8.0.300.0040.00418.77
8.0.290.0000.00816.88
8.0.280.0040.00418.33
8.0.270.0070.00017.30
8.0.260.0000.00716.75
8.0.250.0070.00016.99
8.0.240.0040.00417.05
8.0.230.0070.00016.95
8.0.220.0070.00016.89
8.0.210.0000.00716.86
8.0.200.0000.00616.88
8.0.190.0050.00317.00
8.0.180.0040.00416.91
8.0.170.0060.00316.93
8.0.160.0000.00816.98
8.0.150.0040.00416.91
8.0.140.0040.00416.91
8.0.130.0060.00013.36
8.0.120.0080.00016.91
8.0.110.0000.00716.75
8.0.100.0000.00816.94
8.0.90.0030.00516.88
8.0.80.0080.01316.85
8.0.70.0040.00417.00
8.0.60.0080.00016.91
8.0.50.0040.00416.72
8.0.30.0080.01117.27
8.0.20.0090.00917.40
8.0.10.0040.00417.07
8.0.00.0100.01216.97
7.4.330.0060.00015.01
7.4.320.0000.00616.60
7.4.300.0000.00616.63
7.4.290.0050.00216.63
7.4.280.0000.00816.48
7.4.270.0030.00316.58
7.4.260.0000.00716.61
7.4.250.0000.00716.60
7.4.240.0050.00216.59
7.4.230.0030.00316.33
7.4.220.0070.01016.45
7.4.210.0070.00916.59
7.4.200.0040.00416.70
7.4.190.0000.00716.63
7.4.160.0090.00616.50
7.4.150.0030.01517.40
7.4.140.0100.00817.86
7.4.130.0100.00716.50
7.4.120.0090.00916.64
7.4.110.0070.01016.49
7.4.100.0120.00616.59
7.4.90.0140.01016.57
7.4.80.0120.00419.39
7.4.70.0090.01216.50
7.4.60.0070.01016.58
7.4.50.0080.00016.54
7.4.40.0060.01022.77
7.4.30.0130.00916.64
7.3.330.0030.00313.34
7.3.320.0060.00013.27
7.3.310.0030.00316.36
7.3.300.0070.00016.19
7.3.290.0120.01216.35
7.3.280.0080.01016.36
7.3.270.0060.01117.40
7.3.260.0070.01216.43
7.3.250.0120.00516.38
7.3.240.0140.00916.38
7.3.230.0080.00816.57
7.3.210.0060.01116.38
7.3.200.0070.01019.39
7.3.190.0190.00316.44
7.3.180.0090.00616.61
7.3.170.0120.00516.38
7.3.160.0080.00816.67
7.2.330.0180.00316.39
7.2.320.0130.00316.41
7.2.310.0070.01516.27
7.2.300.0130.00316.33
7.2.290.0030.01316.34
5.4.260.0230.05319.06
5.4.250.0300.04319.21
5.4.240.0300.06719.08
5.4.230.0300.06318.87
5.4.220.0230.07319.09
5.4.210.0230.04319.21
5.4.200.0300.05719.14
5.4.190.0270.03319.05
5.4.180.0300.04019.14
5.4.170.0170.04319.21
5.4.160.0200.06719.17
5.4.150.0200.05019.20
5.4.140.0230.07016.51
5.4.130.0230.07016.51
5.4.120.0230.07016.35
5.4.110.0400.06316.47
5.4.100.0370.03316.41
5.4.90.0330.06316.56
5.4.80.0230.06716.50
5.4.70.0300.05716.26
5.4.60.0230.06716.52
5.4.50.0370.05716.16
5.4.40.0270.06316.16
5.4.30.0230.06316.51
5.4.20.0130.05716.55
5.4.10.0170.03716.32
5.4.00.0130.04015.76
5.3.280.0370.06314.64
5.3.270.0170.07314.45
5.3.260.0230.07314.45
5.3.250.0230.04314.70
5.3.240.0230.04014.44
5.3.230.0270.06014.51
5.3.220.0270.05314.53
5.3.210.0300.04714.42
5.3.200.0270.07314.41
5.3.190.0230.07014.51
5.3.180.0370.06314.42
5.3.170.0300.07014.51
5.3.160.0330.04014.66
5.3.150.0170.07714.42
5.3.140.0230.07314.50
5.3.130.0230.06714.40
5.3.120.0130.05714.64
5.3.110.0230.03314.49
5.3.100.0230.05314.02
5.3.90.0270.05013.84
5.3.80.0170.04014.07
5.3.70.0330.06013.86
5.3.60.0200.04713.79
5.3.50.0200.07313.79
5.3.40.0300.06713.82
5.3.30.0230.05313.86
5.3.20.0330.05713.71
5.3.10.0330.03713.45
5.3.00.0200.05013.59

preferences:
48.06 ms | 400 KiB | 5 Q