我试图将两个数组的数据与条件进行比较。
if ($ valueA == $ valueB) echo selected
我的代码看起来像这样
<select name="credit[]" data-placeholder="Credit..." class="form-control chzn-select col-lg-10" multiple tabindex="4">
<?php
foreach ($looping_fansub->data as $looping_fansub_output) {
foreach ($arr_credit as $credit_data) {
if ($credit_data==$looping_fansub_output['f_name']) {
echo "<option value=".$looping_fansub_output["f_name"]." selected>".$looping_fansub_output["f_name"]."</option>";
}else{
echo "<option value=".$looping_fansub_output["f_name"]." >".$looping_fansub_output["f_name"]."</option>";
}
}
}
?>
</select>
/* Array $looping_fansub->data */
Array(
[0] => Array
(
[f_id] => 4
[f_name] => AlibabaSub
)
[1] => Array
(
[f_id] => 7
[f_name] => Anime Code
[f_link] => http://anime-code.com/
)
[2] => Array
(
[f_id] => 2
[f_name] => Anime Kompi
)
[3] => Array
(
[f_id] => 6
[f_name] => Anti-fansubs
)
[4] => Array
(
[f_id] => 1
[f_name] => AWSubs
)
[5] => Array
(
[f_id] => 3
[f_name] => MoeSubs
)
[6] => Array
(
[f_id] => 5
[f_name] => Subskun
)
)
/* End */
/* Array $credit_data */
Array ( [0] => Subskun [1] => Anime Code [2] => Anime Kompi )
/* End */
我希望结果如下:
但结果是这样的: