Display calendar with PHP with certain conditions

0

I'm starting my PHP studies, and I have the following challenges: Display Sundays in red and Saturdays in bold. Make the calendar start on a day other than a Sunday. but I have no idea how to do this, could anyone tell me how I do that? What logic to use.

    <?php
ini_set("display_errors",1);
ini_set("display_startup_erros",1);
error_reporting(E_ALL);
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>Dom</th>
        <th>Seg</th>
        <th>Ter</th>
        <th>Qua</th>
        <th>Qui</th>
        <th>Sex</th>
        <th>Sáb</th>
    </tr>
    <?php  calendario();?>
</table>
    
asked by anonymous 29.04.2018 / 22:11

1 answer

0

Well. The idea is to use the index of an array where it contains the settings in css: If you have something that was not clear in the code. Just ask that I edit the answer.

<?php
ini_set("display_errors",1);
ini_set("display_startup_erros",1);
error_reporting(E_ALL);
function linha($semana)
{
    $style = ['color:yellow ; background:red', '' , '', '' , '' , '' ,'font-weight: bold' ];
    echo"<tr>";
    for($i = 0; $i<=6;$i++){
        if(isset($semana[$i])){            
            echo '<td' . ' style="' . $style[$i] . '">';
            if($semana[$i] != 0){
                echo "{$semana[$i]}";
            }
            echo '</td>';
        }else{
            echo "<td></td>";
        }
    }
    echo "</tr>";
}
    function Calendario()
    {
        $dia = 0;
        $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>Dom</th>
        <th>Seg</th>
        <th>Ter</th>
        <th>Qua</th>
        <th>Qui</th>
        <th>Sex</th>
        <th>Sáb</th>
    </tr>
    <?php  calendario();?>
</table>
    
29.04.2018 / 22:40