J
J
jakiro10072021-06-01 12:23:59
1C-Bitrix
jakiro1007, 2021-06-01 12:23:59

How to correctly insert values ​​from a php loop into an array?

There is the following code:

CModule::IncludeModule("iblock");

$db_list = CIBlockSection::GetList(array(), array("IBLOCK_ID"=>$arParams["IBLOCK_ID"]), true);
while($ar_result = $db_list->GetNext())
{
  echo $ar_result['NAME']."<br>";

  $db_list_2 = CIBlockSection::GetList(array(), array('SECTION_ID'=>$ar_result['ID']), true);
  while($ar_result_2 = $db_list_2 ->GetNext())
  {
    echo $ar_result_2['NAME']."<br>";

    $res = CIBlockElement::GetList(array(), array('SECTION_ID' => $ar_result_2['ID']), false, false, array());
    while($ob = $res->GetNextElement())
    {
      $arFields = $ob->GetFields();
      print_r('Наименование: '.$arFields['NAME'].' ID:'.$arFields['ID'].'<br>');
    }

  }
}


Outputs the following (via echo and print_r):
Section 1
-Subsection 1
--Item 1 --Item
2
-Subsection 2
--Item 1 Section 1 - Section 1 - Section 1 - Section 2 - Section 2 - Section 1


Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question