how insert or push existing array?
i have code...
$brgys=arrayhelper::map(libbrgy::find() ->where(['city_code'=>$model->city_code]) ->all(),'brgy_code','brgy_name');
the result is..
array(4) { [166816001]=> string(7) "bagyang" [166816002]=> string(5) "baras" [166816003]=> string(8) "bitaugan" [166816004]=> string(7) "bolhoon" }
how add empty value make following...
array(4) { [166816001]=> string(7) "bagyang" [166816002]=> string(5) "baras" [166816003]=> string(8) "bitaugan" [166816004]=> string(7) "bolhoon" ['']=>"" }
so in html form have this..
<select id="tblspbub-brgy_code" class="form-control" name="tblspbub[brgy_code]"> <option value="166816001">bagyang</option> <option value="166816002">baras</option> <option value="166816003">bitaugan</option> <option value="166816004">bolhoon</option> <option value=""></option> </select>
no need modify array achieve this.
drop-down list has special option called prompt
.
<?= $form->field($model, 'code')->dropdownlist($items, ['prompt' => '']) ?>
it render additional option
empty value
in select
given name
.
you can read more here.
Comments
Post a Comment