3v4l.org

run code in 300+ PHP versions simultaneously
<?php class tableutils{ static function compareByName($a, $b){ return strcmp($a, $b); } static function tabella_riassunto ($valori,$cell1,$sort=true,$arr=false,$className='tabella_riassunto',$tot_righe=true,$classi="",$links=""){ /* Scorro l'array per trovare tutte le colonne possibili * TODO: esiste un modo piĆ¹ elegante? */ foreach ($valori as $key => $val) { foreach ($val as $kr => $vr) $col[$kr] = $kr; } if($sort) { sort($col); uksort($valori, 'tableutils::compareByName'); } /* Inizio a scrivere la tabella*/ $table="<table class=\"$className\" celpadding=\"0\" cellspacing=\"0\">"; /* Scrivo le intestazioni */ $table .="<tr>"; $table .="<th>$cell1</th>"; $rex[0][] = $cell1; /* Scrivo le intestazioni */ foreach ($col as $c) { $table .="<th>".$c."</th>";$rex[0][] = $c; } /* Questa colonna serve per i totali */ if($tot_righe) $table .="<th>TOTALE</th>"; //else $table .="<th></th>"; $table .="</tr>"; if($tot_righe)$rex[0][] = "TOTALE"; /* Ciclo l'array*/ $count = 1; foreach ($valori as $key => $val) { $tot1=0; $table .="<tr>"; $table .="<td class=\"nomi\">".$key."</td>"; $rex[$count][] = $key; $count_col=1; foreach ($col as $c){ if(is_array(links)){ if($links[$key][$c]){ if($classi[$count_col]) $table .="<td class=\"".$classi[$count_col]."\"><a href='".$links[$key][$c]."'>".$val[$c]."</a></td>"; else $table .="<td><a href='".$links[$key][$c]."'>".$val[$c]."</a></td>"; } else { if($classi[$count_col]) $table .="<td class=\"".$classi[$count_col]."\">".$val[$c]."</td>"; else $table .="<td>".$val[$c]."</td>"; } } $rex[$count][] = $val[$c]; /* Faccio la somma dei valori degli elementi della riga */ $tot1 += $val[$c]; /* Faccio la somma usando come indice il nome della colonna */ $tot2[$c] += $val[$c]; $count_col++; } if($tot_righe){ $table .="<td class=\"tot1\">".$tot1."</td>"; //else $table .="<td class=\"tot1\"></td>"; $rex[$count][] = $tot1; } $table .="</tr>"; $count++; } /* Scrivo la somma salvata precedentemente*/ $table .="<tr>"; $table .="<td class=\"tot1\">TOTALE</td>"; $rex[$count][] = "TOTALE"; foreach ($tot2 as $t){ $table .="<td class=\"tot1\">".$t."</td>"; $rex[$count][] = $t; $tot += $t; } if($tot_righe){ $table .="<td class=\"totfinal\">".$tot."</td>"; $rex[$count][] = $tot; } $table .="</tr>"; $table .="</table>"; if($arr) return $rex; else return $table; } } $arr = array("052 VARICELLA" => array("2015 m focolai" => 1, "2015 casi coinvolti" => 3)); tableutils::tabella_riassunto($arr);
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught ArgumentCountError: Too few arguments to function tableutils::tabella_riassunto(), 1 passed in /in/NPAiT on line 98 and at least 2 expected in /in/NPAiT:9 Stack trace: #0 /in/NPAiT(98): tableutils::tabella_riassunto(Array) #1 {main} thrown in /in/NPAiT on line 9
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33
Warning: Missing argument 2 for tableutils::tabella_riassunto(), called in /in/NPAiT on line 98 and defined in /in/NPAiT on line 9 Notice: Undefined variable: cell1 in /in/NPAiT on line 26 Notice: Undefined variable: cell1 in /in/NPAiT on line 27 Notice: Use of undefined constant links - assumed 'links' in /in/NPAiT on line 46 Notice: Undefined variable: tot2 in /in/NPAiT on line 60 Notice: Undefined index: 2015 casi coinvolti in /in/NPAiT on line 60 Notice: Use of undefined constant links - assumed 'links' in /in/NPAiT on line 46 Notice: Undefined index: 2015 m focolai in /in/NPAiT on line 60 Notice: Undefined variable: tot in /in/NPAiT on line 78
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Warning: Missing argument 2 for tableutils::tabella_riassunto(), called in /in/NPAiT on line 98 and defined in /in/NPAiT on line 9 Notice: Undefined variable: cell1 in /in/NPAiT on line 26 Notice: Undefined variable: cell1 in /in/NPAiT on line 27 Notice: Use of undefined constant links - assumed 'links' in /in/NPAiT on line 46 Notice: Undefined index: 2015 casi coinvolti in /in/NPAiT on line 60 Notice: Use of undefined constant links - assumed 'links' in /in/NPAiT on line 46 Notice: Undefined index: 2015 m focolai in /in/NPAiT on line 60 Notice: Undefined variable: tot in /in/NPAiT on line 78
Output for 5.0.4 - 5.0.5
Warning: Missing argument 2 for tableutils::tabella_riassunto() in /in/NPAiT on line 9 Warning: uksort(): Invalid comparison function. in /in/NPAiT on line 18 Notice: Use of undefined constant links - assumed 'links' in /in/NPAiT on line 46 Notice: Undefined variable: tot2 in /in/NPAiT on line 60 Notice: Undefined index: 2015 casi coinvolti in /in/NPAiT on line 60 Notice: Use of undefined constant links - assumed 'links' in /in/NPAiT on line 46 Notice: Undefined index: 2015 m focolai in /in/NPAiT on line 60 Notice: Undefined variable: tot in /in/NPAiT on line 78
Output for 5.0.0 - 5.0.3
Warning: Missing argument 2 for tableutils::tabella_riassunto() in /in/NPAiT on line 9 Warning: uksort(): Invalid comparison function. in /in/NPAiT on line 18 Notice: Use of undefined constant links - assumed 'links' in /in/NPAiT on line 46 Notice: Undefined variable: tot2 in /in/NPAiT on line 60 Notice: Undefined index: 2015 casi coinvolti in /in/NPAiT on line 60 Notice: Use of undefined constant links - assumed 'links' in /in/NPAiT on line 46 Notice: Undefined index: 2015 m focolai in /in/NPAiT on line 60 Notice: Undefined variable: tot in /in/NPAiT on line 78
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/NPAiT on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/NPAiT on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/NPAiT on line 5
Process exited with code 255.

preferences:
323.29 ms | 401 KiB | 464 Q