Добро пожаловать!
На самом деле у вас все отлично!
Наше первое упражнение, вероятно, будет выглядеть примерно так:
<?php
// This would the start of our HTML
$html = '<html>
<head>
<title>1</title>
<meta charset="UTF-8">
</head>
<body>';
$names = array("name1", "name2", "name3", "name4", "name5");
// This would the start of our Table
$html .= '<table>';
foreach ($names as $key => $value) {
$html .= '<tr>';
$html .= '<th>' . $key . '</th>';
$html .= '<th>' . $value . '</th>';
$html .= '</tr>';
}
$html .= '</table>';
// This would the end of our HTML
$html .= "</body>
</html>";
// Here, we will be printing it.
echo $html;
Это один из способов сделать это, который мы начинаем с переменной $html
, а затем мы бышаг за шагом добавьте к этому, и, наконец, мы будем печатать его.
Сумма
<?php
$html = '<html>
<head>
<title>1</title>
<meta charset="UTF-8">
</head>
<body>';
$big_numbers_array = [[10, 11, 12], [13, 14, 15]];
// Here we have the sum each row and sum of both rows
echo "<div>Sum of row one is: " . array_sum($big_numbers_array[0]) . "</div>\n";
echo "<div>Sum of row two is: " . array_sum($big_numbers_array[1]) . "</div>\n";
echo "<div>Sum of all rows is: " . (array_sum($big_numbers_array[0]) + array_sum($big_numbers_array[1])) . "</div>\n";
// Here we would be having a table with cumulative sum:
$html = '<table>';
$html .= '<tr>';
$html .= "<td>Number</td>";
foreach ($big_numbers_array as $big_key => $small_numbers_array) {
foreach ($small_numbers_array as $small_key => $number) {
$html .= "<tr>";
$html .= "<th>" . $big_key . ": " . $small_key . "</th>";
$sum += $number;
$html .= "<th>" . $sum . "</th>";
$html .= "</tr>";
}
}
$html .= '</table>';
$html .= "</body>
</html>";
echo $html;
Ошибка
Ошибка в коде быласлово array
перед [
.Ваш код будет выглядеть так:
$html = '<html>
<head>
<title>3</title>
<meta charset="UTF-8">
</head>
<body>';
$value1 = 1;
$value2 = 2;
$value3 = 3;
$value4 = 4;
$value1 = $_POST['value1'];
$value2 = $_POST['value2'];
$value3 = $_POST['value3'];
$value4 = $_POST['value4'];
/*Here i have a doubt, i dont know how to show te values in a div */
echo "<div>1º value: </div>\n";
echo "<div>2º value: </div>\n";
echo "<div>3º value: </div>\n";
echo "<div>4º value: </div>\n";
$finalvalue = [['value1', 'value2'], ['value3', 'value4']];
$html .= "</body>
</html>";