dongzhun4898 2016-05-17 15:11
浏览 102
已采纳

删除数组中具有逗号分隔值的重复项

I have an array of languages that looks like this: (this data is pulled from mysql stored as: e.g. field value: greek, polish)

 Array
(
[0] => 
[1] => french
[2] => french, greek
[3] => german
[4] => greek
[5] => greek, polish
[6] => italian
[7] => spanish
[8] => spanish, italian
[9] => spanish, portuguese
)

I have tried using array_unique($languages) but the output stays the same.

I assume it is because of the comma.

Any idea on how to just have unique values? e.g. one each of: french, greek, german, polish, italian, spanish, and portuguese?

  • 写回答

3条回答 默认 最新

  • dongsi1944 2016-05-17 15:18
    关注

    Make a plain array from input

    $res = array();
    foreach ($array  as $item)
      $res = array_merge($res, explode(', ', $item)); 
    

    and then use array_unique($res)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable