B
B
barder2020-08-09 13:00:57
1C-Bitrix
barder, 2020-08-09 13:00:57

How to select a property from CIBlockResult Object and make an average number?

Hi all.
The bottom line is this: I
select the elements with a filter:

$countOnPage = 3;
    $fastUrlsList = array();
    $arSelect = Array("ID", "NAME", "PREVIEW_TEXT", "PROPERTY_SPRAV", "DATE_CREATE", "PROPERTY_RATING");
  $arFilter = Array("IBLOCK_ID"=>34, "ACTIVE"=>"Y", "PROPERTY_SPRAV"=>$arResult["ID"]);
  $res = CIBlockElement::GetList(array("SORT"=>"ASC"), $arFilter, false, array("nPageSize" => $countOnPage), $arSelect);

the variable Res contains the objects of the elements that are needed.
I need to calculate the average value of the PROPERTY_RATING property
Question : how can I make an array of the PROPERTY_RATING property from an object to work with it?
$Rating = array_sum($a) / count($a)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
scottparker, 2020-08-09
@barder

$a = array();
while($item = $res->fetch()){
$a[] = $item['PROPERTY_RATING'];
}
$Rating = array_sum($a) / count($a)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question