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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别