将数组的php数组转换为单个数组 [英] Converting php array of arrays into single array

查看:44
本文介绍了将数组的php数组转换为单个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组,其值都是特定格式的数组,如下所示:

I have an array whose values are all arrays of a specific format that looks like this:

Array
(
    [0] => Array
           (
               [username] => John
           )    
    [1] => Array
           (
               [username] => Joe
           )
    [2] => Array
           (
               [username] => Jake
           )
)

我想要这个:

Array
(
    [0] => John   
    [1] => Joe
    [2] => Jake
)

我可以使用循环手动执行此操作,但有更好的方法吗?如果不是,是否可以对具有公共属性的对象数组执行此操作?

I can do this manually with a loop but is there a better way? If not, is it possible to do this for an array of objects that have a common attribute?

推荐答案

从 PHP 5.5.0 开始就有一个内置函数 array_column 就是这样做的.

Since PHP 5.5.0 there is a built-in function array_column which does exactly this.

这篇关于将数组的php数组转换为单个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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