dongtuo8170 2017-07-05 04:29
浏览 11
已采纳

如何制作包含最大长度的组合数组?

I have these three arrays:

$arr1 = ['one', 'two', 'three'];
$arr2 = ['three', 'four'];
$arr3 = ['two', 'five', 'six', 'seven'];

And this is expected result:

/* Array
   (
       [0] => one
       [1] => two
       [3] => three
       [4] => four
       [5] => five
       [6] => six
       [7] => seven
   )

Here is my solution which doesn't work as expected:

print_r( array_unique( $arr1 + $arr2 + $arr3) );
/* Array
   (
       [0] => one
       [1] => two
       [2] => three
       [3] => seven
   )

How can I do that?

  • 写回答

5条回答 默认 最新

  • douduoquan2824 2017-07-05 04:34
    关注

    Use this:

    array_unique(array_merge($arr1,$arr2,$arr3), SORT_REGULAR);
    

    this will merge the arrays into one, then removes all duplicates

    Tested Here

    It outputs:

    Array
    (
        [0] => one
        [1] => two
        [2] => three
        [4] => four
        [6] => five
        [7] => six
        [8] => seven
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的