如何展平此数组格式? [英] How can I flatten this array format?

查看:41
本文介绍了如何展平此数组格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试转换以下数组

I am trying to turn the following array

Array
(
    [0] => Array
        (
            [535fd7566a10d96c2ac04d2e26e210c4] => Jane Apple
        )

    [1] => Array
        (
            [3cdacd430d6a70acbe4caf9712a76824] => Johnny Apple
        )
...
)

转换为以下格式。

    Array
    (
                [535fd7566a10d96c2ac04d2e26e210c4] => Jane Apple,
                [3cdacd430d6a70acbe4caf9712a76824] => Johnny Apple,
...
            )

我尝试了一些通过堆栈溢出发现的不同功能,但是谷歌却没有运气。

I have tried a few different functions found through the stack-overflow, and google but no luck.

任何人都对如何实现自己的期望有任何想法结果?

Anyone have any ideas on how I can achieve my desired result?

谢谢,

推荐答案

我相信

array_reduce($array, 'array_merge', [])

应该可以解决问题

基本上,您希望将值数组(每个数组)减少为一个值(数组),因此要减少array_reduce。然后合并将一个项目(数组)合并到另一个数组(在本例中为进位),以生成所需的数组。

essentially you want to reduce an array of values (each an array) to one value (an array) hence array_reduce. and merge takes an item (the array) and merges it with another array (the carry in this case) to produce the array you want.

只想提供一个非循环答案; o)

just wanted to provide a non-loop answer ;o)

这篇关于如何展平此数组格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆