F
F
Forge01002016-05-12 15:33:41
PHP
Forge0100, 2016-05-12 15:33:41

How to remove unnecessary iterations in nested foreach (Smarty)?

Array ($array):

array(1) {
  [2014]=>
  array(2) {
    [7]=> 
    array(1) {
      ["rec"]=>
      array(3) {
        ["accounts_count"]=>
        string(1) "2"
        ["documents_count"]=>
        string(1) "2"
        ["group_type"]=>
        array(1) {
          [0]=>
          array(2) {
            ["value"]=> 
            string(1) "1"       
            ["total_brutto"]=>
            string(7) "5658.00"
          }
        }
      }
    }
    [8]=>
    array(1) {
      ["rec"]=>
      array(3) {
        ["accounts_count"]=>
        string(1) "1"
        ["documents_count"]=>
        string(1) "1"
        ["ecmproducts_group_type"]=>
        array(1) {
          [0]=>
          array(2) {
            ["value"]=>
            string(1) "1"
            ["total_brutto"]=>
            string(8) "12669.00"
          }
        }
      }
    }
  }
}

Code in Smarty:
{foreach from=$array key=year_key item=year}
  {foreach from=$year key=month_key item=month}
    {foreach from=$month key=type_key item=type}
      {foreach from=$type.group_type key=group_type_key item=group_type name=group_type_name}
        <p>{$group_type.value}</p> // Цыкл должен быть 2 раза, но происходит очень много лишних раз
      {/foreach}
    {/foreach}
  {/foreach}
{/foreach}

What check should I put in so that there are no idle cycles? THANKS IN ADVANCE!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2016-05-15
@SilenceOfWinter

{foreach} constructs are {break}, {continue}.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question