donglian4770 2012-04-09 05:11
浏览 48
已采纳

join()PHP函数删除重复的值?

how are you doing? When I use the join() function with duplicated values in an array, the join function returns the array but removing duplicates and I dont want that!

Example:

$array= array(1, 2, 2, 2);
$res = join(',', $array);

I get this:

1,2

but I want the result to be:

1,2,2,2

Hope someone can help me! Thank you

  • 写回答

2条回答 默认 最新

  • drevls8138 2012-04-09 05:48
    关注

    You say this is your code:

    while ($coordenada = mysql_fetch_assoc($resultado)) {
        $arrayX[$coordenada['ARTICULO']] = $coordenada['ARTICULO'];       
        $arrayY[$coordenada['CANTIDAD']] = $coordenada['CANTIDAD']; 
    }
    

    In which case, you are not populating the arrays like you think. Your code is doing this:

    $arrayY[1] = 1;
    $arrayY[2] = 2;
    $arrayY[2] = 2;
    $arrayY[2] = 2;
    

    So only contains 2 values. If you want duplicates, change your code to this:

    while ($coordenada = mysql_fetch_assoc($resultado)) {
        $arrayX[] = $coordenada['ARTICULO'];          
        $arrayY[] = $coordenada['CANTIDAD']; 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块
  • ¥15 nhanes加权logistic回归,svyglm函数