Hello everyone. I'm starting in PHP and I'm having some issues with this code:
<?php
function linha($semana) {
echo "<tr>";
for ($i= 0; $i <= 6; $i++) {
if (isset($semana[$i])) {
echo "<td>{$semana[$i]}</td>";
} else {
echo "<td></td>";
}
}
echo "</tr>";
}
function calendario() {
$dia = 1;
$semana = array();
while ($dia <= 31) {
array_push($semana, $dia);
if (count($semana) == 7) {
linha($semana);
$semana = array();
}
$dia++;
}
linha($semana);
}
?>
<table border="1">
<tr>
<th>Domingo</th>
<th>Segunda</th>
<th>Terça</th>
<th>Quarta</th>
<th>Quinta</th>
<th>Sexta</th>
<th>Sábado</th>
</tr>
<?php calendario();?>
</table>
As you can see, it results in a calendar (no specifics). I can not understand the logic of this code. Why use the for? Why use if?
If anyone can help me with the logic of this code I thank you!