<!DOCTYPE html>
<html lang="es">
    <head>
        <title>Ej 17</title>
        <style>
            .ocupado{
                background-color: green;
            }
            .vacio{
                background-color: gray;
            }
        </style>
        <link rel="stylesheet" href="../webroot/css/ejercicio01.css">
    </head>
    <body>
        <header>
            <h1>Array bidimensional</h1>
        </header>
        <p>
            <?php
            
/*
            * @version 2024/10/8
            * @author Alex Asensio Sanchez                          
            */
                
$aAsientos=[
                    
$aFila1=array_fill(0,15null),
                    
$aFila2=array_fill(0,15null),
                    
$aFila3=array_fill(0,15null),
                    
$aFila4=array_fill(0,15null),
                    
$aFila5=array_fill(0,15null),
                    
$aFila6=array_fill(0,15null),
                    
$aFila7=array_fill(0,15null),
                    
$aFila8=array_fill(0,15null),
                    
$aFila9=array_fill(0,15null),
                    
$aFila10=array_fill(0,15null),
                    
$aFila11=array_fill(0,15null),
                    
$aFila12=array_fill(0,15null),
                    
$aFila13=array_fill(0,15null),
                    
$aFila14=array_fill(0,15null),
                    
$aFila15=array_fill(0,15null),
                    
$aFila16=array_fill(0,15null),
                    
$aFila17=array_fill(0,15null),
                    
$aFila18=array_fill(0,15null),
                    
$aFila19=array_fill(0,15null),
                    
$aFila20=array_fill(0,15null),
                ];
                
                
$aAsientos[6][6]="Alex";
                
$aAsientos[16][9]="Victor";
                
$aAsientos[2][4]="Luis";
                
$aAsientos[10][14]="Jesus";
                
?>
                <table>
                    <?php
                    
echo("<h3>Usando foreach</h3>");
                    foreach(
$aAsientos as $fila){
                        echo(
"<tr>");
                        foreach(
$fila as $asiento){
                            if(
is_null($asiento)){
                                echo(
'<td class="vacio">Vacio</td>');
                            }
                            else{
                                echo(
'<td class="ocupado">'.$asiento.'</td>');
                            }
                            
                        }
                        echo(
"</tr><br>");
                    }
                    
?>
                </table>
                <table>
                    <?php
                    
echo("<h3>Usando while</h3>");
                        
$iPunteroFilas=0;
                        
$iPunteroAsientos=0;                
                        while(
$iPunteroFilas<count($aAsientos)){
                            echo(
"<tr>");
                            while(
$iPunteroAsientos<count($aAsientos[$iPunteroFilas])){ 
                                if(
is_null($aAsientos[$iPunteroFilas][$iPunteroAsientos])){
                                    echo(
'<td class="vacio">Vacio</td>');
                                }
                                else{
                                    echo(
'<td class="ocupado">'.$aAsientos[$iPunteroFilas][$iPunteroAsientos].'</td>');
                                }
                                
$iPunteroAsientos++;
                            }
                            echo(
"</tr>");                            
                            
$iPunteroFilas++;
                            
$iPunteroAsientos=0;
                        }
                    
?>
                </table>
                <table>
                    <?php
                        
echo("<h3>Usando for</h3>");                 
                        for(
$i=0$i<count($aAsientos); $i++){
                            echo(
"<tr>");
                            for(
$j=0$j<count($aAsientos[$i]); $j++){
                                if(
is_null($aAsientos[$i][$j])){
                                    echo(
'<td class="vacio">Vacio</td>');
                                }
                                else{
                                    echo(
'<td class="ocupado">'.$aAsientos[$i][$j].'</td>');
                                }
                            }
                            echo(
"</tr>");
                                                        
                        }
                    
?>
                </table>                           
        </p>
        <footer>
            <p><a href="../../index.html">Alex Asensio Sanchez</a></p>
            <p><a href="../indexProyectoTema3.php">Tema 3</a></p>
            <p><a target="blank" href="https://github.com/AlexAnacardo/204DWESProyectoTema3/tree/developer">GitHub del repositorio</a></p>
        </footer>
    </body>
</html>