douchou8935 2014-05-02 12:30
浏览 27
已采纳

使用复选框数组值并转储到MYSQL中

From a checkbox submit(post) i have an array like this. So this value will be dynamic in form submit. The variable name is $my_values.

Output

    Array
    (
        [0] => 1
        [1] => 2
        [2] => 2_6
        [3] => 3
        [4] => 3_7
        [5] => 3_8
        [6] => 4
        [7] => 4_9
        [8] => 4_10
        [9] => 4_11
        [10] => 4_12
        [11] => 4_13
        [12] => 4_13_14
        [13] => 5
    )

Expected Output

    1,2,3,4,5,6,7,8,9,10,11,12,13,14

So I need to get the output as above in a single variable. How can I achieve that?

In other words :

$my_values is having the array as i have mentioned. i want one more variable $my_results which will convert the array values and give it as a single value with comma seperator (i.e 1,2,3,4,5,6,7,8,9,10,11,12,13,14)

Thanks Kimz

  • 写回答

1条回答 默认 最新

  • dongshendi3599 2014-05-02 12:39
    关注

    if you need each id just once, you can do something like this:

    $tmp = implode(',', $my_values);
    $tmp = str_replace('_', ',', $tmp);
    $idList = explode(',', $tmp);
    $my_results = implode(',', array_unique($idList));
    echo $my_results;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?