'Looping on an HTML table with empty values php

I'm recieving data with school subjects and school marks for each school term.

I try to build an HTML table with this data, but I don't managed to fill it when i have empty values.

Here is my PHP array

Array
(
    [2021-2022] => Array
        (
            [Cuisine] => Array
                (
                    [1] => 3.0
                    [2] => 4.0
                    [3] => 3.0
                    [4] => 3.5
                )

            [Géo] => Array
                (
                    [2] => 6.0
                    [3] => 5.0
                    [4] => 5.0
                )

        )

    [2022-2023] => Array
        (
            [Géo] => Array
                (
                    [1] => 5.0
                )

        )

)

The keys of the array represent the school term number and the values the school marks.

When I loop to make the table, I would like to display all the quarters (placing an n/a if I don't have any value(when the key doesn't exist in facts).



Solution 1:[1]

I finally get the answer :

for($i = 1; $i <= 4 ; $i ++) {
   if(isset($results[$i])){
       echo "<td>" . $results[$i] ."</td>";
   } else {
       echo "<td></td>";
   }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bix