A
A
Artyom Suzenko2019-10-29 12:28:59
1C-Bitrix
Artyom Suzenko, 2019-10-29 12:28:59

Why doesn't it display the partition ID?

<?php
    $strQueryText = "/path/to/xml/file.xml";
    $objXML = new CDataXML();
    $objXML->Load($strQueryText);
    $arData = $objXML->GetArray();

    $arResult = array();
    foreach ($arData['items']['#']['item'] as $arValue) {
        $ar = array();
        foreach ($arValue['#'] as $sKey => $sVal) {
            $ar[$sKey] = $sVal[0]['#'];
        }
        $arResult[] = $ar;
    }

    $j = 0;
    $sk = array();
    foreach ($arResult as $qwe => $new) {
        $id[$j]['guid_item'] = $new['guid_item'];
        $i = 0;

        while (count($new['related_folders']['guid_folder']) > $i) {
            $id[$j]['guid_folder'][$i] = $new['related_folders']['guid_folder'][$i]['#'];
            $i++;
        }
        $j++;
    }

    $col = count($id);

    for ($i = 0; $i <= $col; $i++) {
        $res = CIBlockElement::GetList(array(), array('IBLOCK_ID' => 10, 'XML_ID' => $id[$i]['guid_item'], 'SITE_ID' => "s1"));
        $item = $res->Fetch();
        echo "item_id: " . $item["ID"] . "<br>";

        $k = 0;
        $myArr = $id[$i]['guid_folder']; // не выводит
        //$myArr = array('8f50834b-7f76-42c1-a019-3b3b29d93c40','37728a3a-0a97-4f16-a272-f0a8d7842d99'); // выводит
        foreach ($myArr as $dope => $now) {

            $fSections = CIBlockSection::GetList(
                            false, Array("IBLOCK_ID" => 10, "XML_ID" => $myArr[$k]), false, Array("ID"), false
            );
            while ($flSections = $res->getNext()) {
                echo "folder_id: " . $flSections['ID'] . "<br>";
            }
            $k++;
        }
    }

If you specify an array created manually, then it works correctly:
//$myArr = $id[$i]['guid_folder'];
$myArr = array('8f50834b-7f76-42c1-a019-3b3b29d93c40','37728a3a-0a97-4f16-a272-f0a8d7842d99');

Otherwise, $flSections is empty (((
With print_r, the arrays have an identical format. Tell me what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Shchuchkin, 2019-10-29
@CrewGer

and he doesn't need typecasting like SimpleXML by any chance?
(string) $flSections['ID']

A
Artyom Suzenko, 2019-11-01
@CrewGer

The problem was that there were non-existent GUIDs in the XML file.
Ahaha)))
Krch working code)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question