php - Set of Excises arrays, vectors and more array Pt 1
I started studying recently and my friend passed me these exercises, but it seems that it is still too early for me I'm having difficulty building tables with arrays and vectors I even tried to try to do it on my own, but the video lessons did not show much related to the exercises that my friend passed to me
<!--Include 5 values in a vector, and then display all values in an HTML table using for or foreach-->
<?php
$name = array ("$name1", "$name2", "$name3", $name4 $name5);
/*Here I do not know how to add values to the names in the array using post
Much less For and Foreach
*/
?>
<html>
<head>
<title>1</title>
<meta charset="UTF-8">
</head>
<body>
<table method="post">
<tr>
<th>Names</th>
<th></th>
</tr>
<tr>
<td>1</td>
<td></td>
</tr>
<tr>
<td>2</td>
<td></td>
</tr>
<tr>
<td>3</td>
<td></td>
</tr>
<tr>
<td>4</td>
<td></td>
</tr>
<tr>
<td>5</td>
<td></td>
</tr>
</table>
</body>
</html>
Well, i tried my best to do it, but i don't know and didn't get it all over, can you help me?
<!-- Read 4 numbers via POST, place them in a vector and show them on screen -->
<?php
$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 = array [['value1', 'value2'],['value3', 'value4']];
echo $finalvalue;
$html .= "</body>
</html>";
Answer
Solution:
Welcome!
You are actually doing pretty great!
Our first exercise would likely look like something similar to:
This is one way to do that, which we would be starting with a
$html
variable, and then we would step by step add to that, and finally we will be printing it.Sum
Bug
The bug in the code was the word
array
before[
. Your code would look like: