gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 13:39:48 24 4
gpt4 key购买 nike

我有这三个数组:

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

这是预期的结果:

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

Here我的解决方案没有按预期工作:

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

我该怎么做?

最佳答案

使用这个:

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

这会将数组合并为一个,然后删除所有重复项

已测试 Here

输出:

Array
(
[0] => one
[1] => two
[2] => three
[4] => four
[6] => five
[7] => six
[8] => seven
)

关于php - 如何制作包含最大长度的组合数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44917042/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com