Answer the question
In order to leave comments, you need to log in
How to filter an associative array?
There is a php code, I get an associative array of $result elements. Please tell me how to filter the array by the string property PROPERTY_SHOW
That is, in the end, only elements with the PROPERTY_SHOW property that have the value Y should get into the $result array
<?
if (CModule::IncludeModule("iblock")):
$iblock_id = 36;
# show url my elements
$my_elements = CIBlockElement::GetList (
Array("ID" => "ASC"),
Array("IBLOCK_ID" => $iblock_id),
false,
false,
Array('ID', 'NAME', 'PROPERTY_PRICE', 'DETAIL_PAGE_URL')
);
$result = [];
while ($ar_fields = $my_elements->GetNext()) {
$result[] = $ar_fields;
};
endif;
?>
Answer the question
In order to leave comments, you need to log in
$result = [];
while ($ar_fields = $my_elements->GetNext()) {
if ($ar_fields['PROPERTY_SHOW_VALUE'] === 'Y'){
$result[] = $ar_fields;
}
};
Have you tried adding it to the filter?
$my_elements = CIBlockElement::GetList (
Array("ID" => "ASC"),
Array("IBLOCK_ID" => $iblock_id, 'PROPERTY_SHOW'=>'Y'),
false,
false,
Array('ID', 'NAME', 'PROPERTY_PRICE', 'DETAIL_PAGE_URL')
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question