V
V
venom19962021-03-03 10:56:28
Bitrix24
venom1996, 2021-03-03 10:56:28

How to substitute the value of the array at each iteration?

$arFilterOplataPoSchetam = array("IBLOCK_ID" => "89", "ID" => $arProps['OPLATY_PO_SCHETAM']['VALUE'][0], ">=DATE_CREATE" => $minDate,
            "<=DATE_CREATE" => $maxDate,);

        $summaPlatejeiDolgNaDatu = 0;

        $resOplataPoSchetamDluaDolgNaDatu = CIBlockElement::GetList(
            array("DATE_CREATE" => 'ASC'),
            $arFilterOplataPoSchetam,
            false,
            array(),
            $arSelectOplataPoSchetam
        );


        while ($obOplataPoSchetamDluaDolgNaDatu = $resOplataPoSchetamDluaDolgNaDatu->GetNextElement()) {
            $arFieldsOplataPoSchetamDluaDolgNaDatu = $obOplataPoSchetamDluaDolgNaDatu->GetFields();
        }

$arProps['OPLATY_PO_SCHETAM']['VALUE'] array can have more elements and I need to supply these values ​​to $arFilterOplataPoSchetam in ID and iterate to print the whole array for each element $arProps['OPLATY_PO_SCHETAM'][' VALUE']

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikolaev, 2021-03-05
@gromdron

Please structure your code so that there are no jumping indents.
As for the task, if $arProps['OPLATY_PO_SCHETAM']['VALUE'] contains an array of identifiers, then this will also work.
That is, if yours looks like:

$arProps['OPLATY_PO_SCHETAM']['VALUE'] = [
    1,
    2,
    3,
    4
];

Then you just need to replace your filter with
$arFilterOplataPoSchetam = array(
    "IBLOCK_ID" => "89",
    "ID" => $arProps['OPLATY_PO_SCHETAM']['VALUE'],
    ">=DATE_CREATE" => $minDate,
    "<=DATE_CREATE" => $maxDate
);

Those. remove "[0]"
As soon as you do that, you will get back an array of elements, but in your code in $arFieldsOplataPoSchetamDluaDolgNaDatu there will always be 1 result - the last one.
To prevent this, you need to add the results somewhere.
For example do this:
$debtsOnDate = [];

while ($obOplataPoSchetamDluaDolgNaDatu = $resOplataPoSchetamDluaDolgNaDatu->GetNextElement()) {
    $debtsOnDate[] = $obOplataPoSchetamDluaDolgNaDatu->GetFields();
}

And after you do this, you can also speed up the whole cycle (removing unnecessary requests):
while ( $debtOnDate = $resOplataPoSchetamDluaDolgNaDatu->GetNext() )
{
    $debtsOnDate[] = $debtOnDate;
}

And of course, if no output is intended for the user (for example, only a count is needed), then you can replace GetNext with the Fetch method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question