我在formbuilder api工作,我在跟随数组
后面跟随函数Array
(
[label] => Course
[field_type] => checkboxes
[required] => 1
[field_options] => stdClass Object
(
[options] => Array
(
[0] => stdClass Object
(
[label] => BE
[checked] =>
)
[1] => stdClass Object
(
[label] => MBA
[checked] =>
)
)
)
[cid] => c11
)
价值:BE
如何在选项数组中的label = BE处设置checked = 1 ...请帮我这样做
答案 0 :(得分:1)
假设您的数组位于名为$fb
的变量中。
简单且可能无用的答案是: -
$fb['field_options']->options[0]->checked = 1;
但是,如果您只知道要将checked = 1
设置为label = 'BE'
,那么您将不得不寻找正确的变更位置。
foreach ( $fb['field_options']->options as $option ) {
if ( $option->label == 'BE' ) {
$option->checked = 1;
}
}