3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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($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);
based on NPAiT
Output for 7.1.0 - 7.2.6
Fatal error: Uncaught ArgumentCountError: Too few arguments to function tableutils::tabella_riassunto(), 1 passed in /in/vk5s1 on line 98 and at least 2 expected in /in/vk5s1:9 Stack trace: #0 /in/vk5s1(98): tableutils::tabella_riassunto(Array) #1 {main} thrown in /in/vk5s1 on line 9
Process exited with code 255.
Output for 5.4.0 - 7.0.20
Warning: Missing argument 2 for tableutils::tabella_riassunto(), called in /in/vk5s1 on line 98 and defined in /in/vk5s1 on line 9 Notice: Undefined variable: cell1 in /in/vk5s1 on line 26 Notice: Undefined variable: cell1 in /in/vk5s1 on line 27 Notice: A non well formed numeric value encountered in /in/vk5s1 on line 47 Notice: Uninitialized string offset: 52 in /in/vk5s1 on line 47 Notice: A non well formed numeric value encountered in /in/vk5s1 on line 47 Notice: Uninitialized string offset: 2015 in /in/vk5s1 on line 47 Notice: Uninitialized string offset: 1 in /in/vk5s1 on line 52 Notice: Undefined variable: tot2 in /in/vk5s1 on line 60 Notice: Undefined index: 2015 casi coinvolti in /in/vk5s1 on line 60 Notice: A non well formed numeric value encountered in /in/vk5s1 on line 47 Notice: Uninitialized string offset: 52 in /in/vk5s1 on line 47 Notice: A non well formed numeric value encountered in /in/vk5s1 on line 47 Notice: Uninitialized string offset: 2015 in /in/vk5s1 on line 47 Notice: Uninitialized string offset: 2 in /in/vk5s1 on line 52 Notice: Undefined index: 2015 m focolai in /in/vk5s1 on line 60 Notice: Undefined variable: tot in /in/vk5s1 on line 78
Output for 5.2.10 - 5.3.29
Warning: Missing argument 2 for tableutils::tabella_riassunto(), called in /in/vk5s1 on line 98 and defined in /in/vk5s1 on line 9 Notice: Undefined variable: cell1 in /in/vk5s1 on line 26 Notice: Undefined variable: cell1 in /in/vk5s1 on line 27 Notice: Uninitialized string offset: 52 in /in/vk5s1 on line 47 Fatal error: Cannot use string offset as an array in /in/vk5s1 on line 47
Process exited with code 255.
Output for 5.1.0 - 5.2.9
Warning: Missing argument 2 for tableutils::tabella_riassunto(), called in /in/vk5s1 on line 98 and defined in /in/vk5s1 on line 9 Notice: Undefined variable: cell1 in /in/vk5s1 on line 26 Notice: Undefined variable: cell1 in /in/vk5s1 on line 27 Fatal error: Cannot use string offset as an array in /in/vk5s1 on line 47
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Missing argument 2 for tableutils::tabella_riassunto() in /in/vk5s1 on line 9 Warning: uksort(): Invalid comparison function. in /in/vk5s1 on line 18 Fatal error: Cannot use string offset as an array in /in/vk5s1 on line 47
Process exited with code 255.
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/vk5s1 on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/vk5s1 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/vk5s1 on line 5
Process exited with code 255.