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 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度