我有两个数组,第一个是
"[attr.disabled]": "disabled ? true : null"
,第二个是$practice_areas = array(
array(
"id" => 1,
"name" => "Administrative",
"form_id" => 1
),
array(
"id" => 2,
"name" => "Admiralty & Maritime",
"form_id" => 1
),
array(
"id" => 3,
"name" => "Agricultural",
"form_id" => 1
),
array(
"id" => 4,
"name" => "Alternative Dispute Resulution",
"form_id" => 1
),
array(
"id" => 5,
"name" => "Antitrust & Trade Regulation",
"form_id" => 1
),
array(
"id" => 6,
"name" => "Appellate Practice",
"form_id" => 1
)
);
$selected_id
这是我目前的代码:
$selected_id = array(
array(
"id" => 1,
"lawyer_id" => 2,
"practice_area_id" => 3
),
array(
"id" => 2,
"lawyer_id" => 2,
"practice_area_id" => 4
)
);
我想选择<label>Practice area(s) *</label>
<select id="practice_areas" multiple="multiple" name="practice_areas[]">
<option value="" selected="selected"></option>
<?php foreach($practice_areas as $practice_area) {?>
<option value="<?php $practice_area['id'] ?>" <?php ($selected_id->practice_area_id == $practice_area['id']) ? 'selected="selected"' : ''; ?>><?php $practice_area['name'] ?></option>
<?php } ?>
</select>
数组中存在的所有选项。我正好在正确地编写这个循环。
EDIT1
当我尝试使用
时$selected_id
我得到了这个结果。
foreach ($selected_id as $sel) {
$is_selected[$sel["practice_area_id"]] = true;
}