php array 递归_递归Array.flat

php array 递归

There was much talk about Array.prototype.flat during its early stages, starting with the name alone. Many developers preferred the name flatten but the spec differed from MooTools' implementation. MooTools would recursively flatten an array but the new, official flat implementation defaults one level of flattening,.

Array.prototype.flat的早期阶段就进行了很多讨论,仅从名称开始。 许多开发人员更喜欢使用flatten这个名称,但其规范与MooTools的实现有所不同。 MooTools会递归地展平数组,但是新的官flat实现默认为展平一个级别。

The current implementation of Array.prototype.flat is:

Array.prototype.flat的当前实现是:

[1, 2, [3], [[4]]].flat(/* depth */);
// [1,2,3,[4]]

.flat only flattens arrays to one level by default, but what if you want a truly flattened array? You can use Infinity and flat's depth argument to make that happen:

默认情况下, .flat仅将数组.flat平到一个级别,但是如果您想要真正展平的数组怎么办? 您可以使用Infinityflatdepth参数来实现:

[1, 2, [3], [[4]], [[[[[[6]]]]]]].flat(Infinity);
// [1,2,3,4,6]

I find the method name a bit misleading but I understand why they went to a single level. The method name smush was thrown around, which would've been the worst method name since stringify!

我发现方法名称有点令人误解,但我理解为什么它们进入了单个级别。 方法名称smush被抛出,这是自stringify以来最糟糕的方法名称!

翻译自: https://davidwalsh.name/recursive-array-flat

php array 递归

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值