doushi3715 2014-02-21 06:47
浏览 68

在$ _GET中使用implode

I have some forms in my page like :

    <form method="get">
Enter Your Firstname :<input type="text" name="t1"  />
Enter Your Lastname :<input type="text" name="t2"  />
<input type="submit" name="sb" />
</form>

so users will fill this form and i want to have values of this form separated with comma

for example

John,Smith
James,Baker

so here is my php code

if ( isset ($_GET['sb']))
{
    $t_array = array("t1","t2");
    foreach ( $t_array as $key ) 
    {
        echo implode(',' , $_GET[$key]);
    }
}

When i try to do this , i got this error :

Warning: implode() [<a href='function.implode'>function.implode</a>]: Invalid arguments passed in PATH on line 24

i don't know why i can't use implode in $_GET or $_POST

so how can i solve this problem ?

P.S : i want to use array and implode in my page , please don't write about other ways

  • 写回答

4条回答 默认 最新

  • dongzhenbi8919 2014-02-21 06:50
    关注

    What you need is something like below, you don't actually need implode for this:

    if ( isset ($_GET['sb']))
    {
        $t_array = array("t1","t2");
        $result = '';
        foreach ( $t_array as $key ) 
        {
            if ($result != '') $result .= ',';
            $result .= $_GET[$key];
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名