Answer the question
In order to leave comments, you need to log in
PHP: How to set an element of an array without extra code?
Good day
There is a piece of code for SELECT fields (YII2 framework)
->dropDownList($structure_enum, [
'class' => 'form__select',
'style' => 'width: 100%;',
])
->dropDownList($structure_enum, [
'class' => 'form__select',
'style' => 'width: 100%;',
$structure_strict ? 'disabled' => 'disabled' : '',
])
$a = [
'class' => 'form__select',
'style' => 'width: 100%;',
];
if ($structure_strict) $a ['disabled'] = 'disabled';
.....
->dropDownList($structure_enum, $a)
Answer the question
In order to leave comments, you need to log in
As an option to glue arrays:
->dropDownList($structure_enum, array_merge(
[ 'class' => 'form__select', 'style' => 'width: 100%;' ],
($structure_strict) ? [ 'disabled' => 'disabled' ] : []
))
<?php
->dropDownList($structure_enum, array_filter([
'class' => 'form__select',
'style' => 'width: 100%;',
'disabled' => $structure_strict ? 'disabled' : false,
]));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question