我有两个阵列,First Array:
print_r($store_name);
Array ( [0] => PAM-Penang Alma [1] => PBL-Bayan Lepas [2] => PBM-Bukit Mertajam [3] => PBR-Jalan Burma [4] => PGL-Greenlane Penang [5] => PRU-Penang Raja Uda [6] => PSC-Sunway Carnival [7] => PSP-Sunway Prima [8] => PTB-Penang Tg Bungah )
我的第二个数组:
print_r ($store_id_arr);
Array ( [0] => 815 [1] => 817 [2] => 819 [3] => 821 [4] => 823 [5] => 825 [6] => 827 [7] => 829 [8] => 831 )
如何使用select(如下所示)组合两个数组?:
<select>
<option value="$store_id_arr">$store_name</option>
<option value="$store_id_arr">$store_name</option>
</select>
答案 0 :(得分:2)
echo '<select>';
foreach ($store_id_arr as $k => $v) {
echo '<option value="'.$v.'">'.$store_name[$k].'</option>';
}
echo '</select>';
非常简单,它在$store_id_arr
上迭代,并使用与id相同的键获取name的值
答案 1 :(得分:2)
这必须帮助你
<select>
<?php
foreach($store_name as $key=>$value)
{
?>
<option value="<?php echo $store_id_arr[$key] ?>"><?php echo $value ?></option>
<?php
}
?>
</select>