Display the year and month that is coming from the array

3

I can already display the year within the foreach by the position, how do I display the month too?

The array is coming like this, the month in case would be that 3, 2, 3, 4 wanted to display this value inside my foreach (this is the var_dump in the variable files)

    array (size=2)
  2016 => 
    array (size=1)
      3 => 
        array (size=1)
          2 => 
            object(stdClass)[44]
              ...
  2017 => 
    array (size=3)
      2 => 
        array (size=1)
          1 => 
            object(stdClass)[45]
              ...
      3 => 
        array (size=1)
          3 => 
            object(stdClass)[46]
              ...
      4 => 
        array (size=1)
          2 => 
            object(stdClass)[47]
              ...

This is my foreach, how could I do that?

<ul class="blogcat">
                        <?php foreach ($arquivos as $k => $a): ?>
                            <li>
                                <a href="#"><?= $k; ?></a>
                                <ul>
                                    <li><a href="#"><?= 'exibir o mes' ?></a></li>
                                </ul>
                            </li>
                        <?php endforeach; ?>
                    </ul>
    
asked by anonymous 05.04.2017 / 19:46

1 answer

3

What you have is an array, a multi-dimensional array.

To solve this question you will need to nest a foreach inside another. It would be basically this:

<ul class="blogcat">
    <?php foreach ($arquivos as $indice1 => $valor1): ?>
        <li>
            <a href="#"><?= $indice1; ?></a>
            <ul>
                <?php foreach ($valor1 as $indice2 => $valor2): ?>
                    <li><a href="#"><?= $indice2; ?></a></li>
                <?php endforeach; ?>
            </ul>
        </li>
    <?php endforeach; ?>
</ul>

If you intend to display the days too, just follow the same reasoning.

    
05.04.2017 / 19:56