T
T
Torna2015-07-03 03:22:25
PHP
Torna, 2015-07-03 03:22:25

What is the correct way to loop in Twig?

There is an array

Array
(
    [0] => Array
        (
            [7] => Июль
            [8] => Август
            [9] => Сентябрь
            [10] => Октябрь
            [11] => Ноябрь
            [12] => Декабрь
        )

    [1] => Array
        (
            [7] => 19
            [8] => 18
            [9] => 11
            [10] => 4
            [11] => 3
            [12] => 1
        )

)

How to properly loop in Twig to get:
{% for key, value in leftMonth %}
  <li>
    <a href="?month={{key}}&year={{year}}">{{value}}</a>
      <span class="leftbar-count">
          <small>{{value2}}</small>
      </span>
  </li>
{% endfor %}

How to select from an array?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gregory, 2015-07-03
@difiso

Something like this.

foreach($arr[0] as $key => $value)
{
$month = $key;
$month_name = $value;
$data = $arr[1][$key]; // цифирка во втором массиве
}

Change it to Twig syntax yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question