在阵列移动阵列父阵列PHP [英] Move array in array to parent array php

查看:92
本文介绍了在阵列移动阵列父阵列PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有移动阵列是在阵列到母体数组作为键或值的特定功能。

Is there a specific function to move array which is in array to the parent array as key or value.

array(5) { [0]=> array(1) { [0]=> string(2) "id" } [1]=> array(1) { [0]=> string(7)
"buydate" } [2]=> array(1) { [0]=> string(6) "expire" } [3]=> array(1) { [0]=> string(6) 
"planid" } [4]=> array(1) { [0]=> string(5) "buyer" } } 

结果,我想获得的是:

Result I would like to get is:

array() { [0] => 'id', [1] => 'buydate' etc. }

或者

array('id', 'buydate' etc.. )

是否有可能实现无的foreach?

Is it possible to achieve without foreach ?

推荐答案

array_map()是非常强大的,应该做的伎俩:

array_map() is extremely powerful and should do the trick:

$array = ... ; // your initial array
$flattened_array = array_map(function($item) {
    return $item[0];
}, $array);

这篇关于在阵列移动阵列父阵列PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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