$a = array (array(0=>"яблоко",
1=>"1-01-2019",
2=>"1"),
array(0=>"апельсин",
1=>"2-01-2019",
2=>"2"),
array(0=>"мандарин",
1=>"2-01-2019",
2=>"3"));
$table = '<table style="border:1px solid">
<tr style="border:1px solid">
<td style="border:1px solid">Название</td>';
for($i=0;$i<count($a);$i++) {
$table .= ' <td style="border:1px solid">' . $a[$i][1] . '</td>';
}
$table .= ' </tr>';
for($i=0;$i<count($a);$i++) {
$table .= '<tr style="border:1px solid">';
$table .= ' <td style="border:1px solid">'.$a[$i][0].'</td>';
$table .= '</tr>';
}
if(???????????){
}
echo $table;
$data = [
["яблоко", "1-01-2019", "1"],
["апельсин", "2-01-2019", "2"],
["мандарин", "2-01-2019", "3"]
];
function buildTable($data) {
$html = "<table>";
/* Build header */
$html .= "<tr>
<td>Название</td>";
foreach ($data as $element) {
list($fruit, $date, $number) = $element;
$html .= "<td>{$date}</td>";
}
$html .= "</tr>";
/* Build body */
foreach ($data as $element) {
list($fruit, $date, $number) = $element;
$html .= "<tr>";
$html .= "<td>{$fruit}</td>";
foreach ($data as $index=>$el) {
$html .= "<td>";
$html .= ($index+1) == $number ? $number : null;
$html .= "</td>";
}
$html .= "</tr>";
}
$html .= "</table>";
return $html;
}