dongxilan9351
2013-01-09 19:36
浏览 43
已采纳

将数组作为选项的值传递给表单

I'm currently trying to send an array as the value of an option in a select but I cannot access the data after the form is sent.

echo '<select id="domainResults_domaines" name="domainResults_domaines">';
foreach($domainsFound as $domain){
    echo '<option value="'.$domain.'">'.$domain['domaine'].'</option>';
}
echo '</select>';

The $domain array contains 2 values and I want to be able to access both of those after sending the form. Is there a way to send the array as the value or is there another way to pass 2 variables in a single option?

Thanks for the help.

图片转代码服务由CSDN问答提供 功能建议

我目前正在尝试将数组作为select中的选项值发送但我无法访问数据 表单发送后。

  echo'&lt; select id =“domainResults_domaines”name =“domainResults_domaines”&gt;'; 
foreach($ domainsFound as $ domain){\  n echo'&lt; option value =“'。$ domain。'”&gt;'。$ domain ['domaine']。'&lt; / option&gt;'; 
} 
echo'&lt; / select&gt;'; \  n   
 
 

$ domain 数组包含2个值,我希望能够在发送表单后访问这两个值。 有没有办法将数组作为值发送,还是有另一种方法可以在一个选项中传递2个变量?

感谢您的帮助。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanjuebiao6730 2013-01-09 19:38
    已采纳

    Try:

    echo '<select id="domainResults_domaines" name="domainResults_domaines">';
    foreach($domainsFound as $key=>$value){
        echo '<option value="'.$key.'">'.$value.'</option>';
    }
    echo '</select>';
    

    Check out PHP foreach.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dongshandun4363 2013-01-09 19:39

    Value has to be string, you could use something like json_encode to set the value and json_decode to get the array back on server side.

    foreach($domainsFound as $domain){
        echo '<option value="'.htmlspecialchars(json_encode($domain)).'">'.$domain['domaine'].'</option>';
    }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题