我想从两个多维数组中选择选项 这是两个数组
我正在使用2 for循环,但是当我选择了超过1个选项时,它无效。
Array ( [0] => stdClass Object ( [id] => 21 [name] => mentor_add ) [1] => stdClass Object ( [id] => 1 [name] => users_add ) [2] => stdClass Object ( [id] => 3 [name] => users_delete ) [3] => stdClass Object ( [id] => 2 [name] => users_edit ) [4] => stdClass Object ( [id] => 4 [name] => users_view ) ) Array ( [0] => stdClass Object ( [perm_id] => 1 [user_id] => 1 ) [1] => stdClass Object ( [perm_id] => 21 [user_id] => 1 ) )
我正在为render html编写这段代码:
$html .= '<select name = "perms[]" class="chosen-multiple-select" multiple="multiple" style="width:510px">';
foreach ($rec as $v) {
foreach ($sql2 as $sv) {
if ($sv->perm_id == $v->id) {
$selected = ' selected="selected"';
} else {
$selected = '';
}
$html .= '<option ' . $selected . ' value=' . $v->id . '>' . $v->name . '</option>';
}
}
$html .= '</select>';