简体   繁体   English

如何为 select 输入动态设置数组选项

[英]how to set array options dynamically for select input

I want similar like this我想要类似这样的

    array( 'id' => 'course-level', 'name' => 'Level of Study', 'type' => 'select', 'options' => array(
        ''  => 'Select one',
        foreach($values as $value) {
            echo $value->id ." => ". $value->title.",";
        }               
    ),  'allow_none' => false, 'repeatable' => false
)

please help me thank you.请帮帮我,谢谢。

use array_map使用 array_map

$newArray = array_map(function($item) use ($values) {
    $newItem = array();
    $newItem['id'] = $item['id'];
    $newItem['name'] = $item['name'];
    $newItem['type'] = $item['type'];
    foreach($values as $value)
        $newItem['options'][$values->id] = $value->title;
    return $newItem;

},$oldArray);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何动态更改选择的选项? - How to change options of select dynamically? 如何在Codeigniter中放大多个选择选项输入数组 - How To Implode Multiple Select Options Input Array in Codeigniter 默认情况下如何从数组设置多个选择选项 - How to set multiple select options by default from array 如何根据php数组将预选选项设置为多选标记 - How to set preselected options into a multiple select tag according to a php array 如何使用JQuery动态创建选择选项? - How to dynamically create Select Options using JQuery? 在Magento Admin面板的目录产品页面中动态设置选择选项 - Set select options dynamically in catalog product page in Magento Admin panel 加载时将选定的选项设置为PHP多选输入 - Set selected options into PHP multi-select input while loading 如何使用PHP在选择框中选择从多个选项或具有不同值的数组到视图的设置选项 - How to set an option from multiple options or array with different values to views as selected in select box using PHP JQUERY根据来自另一个选择元素的输入动态填充“选择”选项 - JQUERY Populate “Select” options dynamically based on input from another select element 如何动态设置 Javascript 中的数组? - How to set an Array in Javascript dynamically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM