从多维数组Array_values [英] Array_values from multidimensional array
本文介绍了从多维数组Array_values的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
该阵列看起来像
$ ARR =阵列( 阵列('一个','B'),
阵列('C','D'),
阵列(E,F),)
和我想从第一列得到与值的数组,如阵列('A','C','E')
我知道它可以很容易地通过遍历数组和值存储在另一个阵列来完成,但有一个较短的方式,内置PHP函数什么的?
解决方案
$ ARR =阵列( 阵列('一个','B'),
阵列('C','D'),
阵列(E,F),);//你可以把它用array_map看起来简洁:)
$ ARR = array_map(函数($ X){返回$ X [0];} $ ARR);// $ ARR =阵列('A','C','E');
The array looks like
$arr = array(
array('a', 'b'),
array('c', 'd'),
array('e', 'f'),
)
And I want to get an array with values from the first column, like array('a', 'c', 'e')
I know it can easily be done by iterating the array and store the values in another array, but is there a shorter way, a built-in PHP function or something?
解决方案
$arr = array(
array('a', 'b'),
array('c', 'd'),
array('e', 'f'),
);
// You can make it look concise using array_map :)
$arr = array_map(function($x){ return $x[0]; }, $arr);
// $arr = array('a', 'c', 'e');
这篇关于从多维数组Array_values的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文