Answer the question
In order to leave comments, you need to log in
Creating an object in an array with a condition. What am I doing wrong?
There is a code:
<?
$arrProgressBuilds = [
[
'name' => $arResult[PROPERTIES][per1][NAME],
],
[
'name' => $arResult[PROPERTIES][per2][NAME],
],
[
'name' => $arResult[PROPERTIES][per3][NAME],
],
];
$countArrBuilds = count($arrProgressBuilds);
$countClassBuilds = [
'2' => '6',
'4' => '4',
'6' => '4',
'8' => '3'
];
?>
<?
$arrProgressBuilds = [
if (!empty($arResult[PROPERTIES][per1][VALUE])) {
[
'name' => $arResult[PROPERTIES][per1][NAME],
],
}
if (!empty($arResult[PROPERTIES][per2][VALUE])) {
[
'name' => $arResult[PROPERTIES][per2][NAME],
],
}
if (!empty($arResult[PROPERTIES][per3][VALUE])) {
[
'name' => $arResult[PROPERTIES][per3][NAME],
],
}
$countArrBuilds = count($arrProgressBuilds);
$countClassBuilds = [
'2' => '6',
'4' => '4',
'6' => '4',
'8' => '3'
];
?>
Answer the question
In order to leave comments, you need to log in
The condition inside the declaration. Change to:
$arrProgressBuilds = [];
if (!empty($arResult['PROPERTIES']['per1']['VALUE'])) {
$arrProgressBuilds[] = [
'name' => $arResult['PROPERTIES']['per1']['NAME'],
];
}
if (!empty($arResult['PROPERTIES']['per2']['VALUE'])) {
$arrProgressBuilds[] = [
'name' => $arResult['PROPERTIES']['per2']['NAME'],
];
}
if (!empty($arResult['PROPERTIES']['per3']['VALUE'])) {
$arrProgressBuilds[] = [
'name' => $arResult['PROPERTIES']['per3']['NAME'],
];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question