将两个不同但索引相同的数组放入Select


Put two different Array but same index into Select

我有两个数组,第一个数组:

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>
echo '<select>';
foreach ($store_id_arr as $k => $v) {
    echo '<option value="'.$v.'">'.$store_name[$k].'</option>';
}
echo '</select>';

非常简单,它在$store_id_arr上迭代,并使用与id 相同的键获取name的值

这必须帮助您

<select>
    <?php
    foreach($store_name as $key=>$value)
    {
    ?>
  <option value="<?php echo $store_id_arr[$key] ?>"><?php echo $value ?></option>
  <?php
    }
    ?>
</select>