创建多维数组的数组 [英] Create an array from multidimensional array
本文介绍了创建多维数组的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下数组:
array (size=2)
0 =>
array (size=4)
0 => string 'http://localhost/wp/wp-content/uploads/2013/03/slider-area.jpg' (length=62)
1 => int 1584
2 => int 346
3 => boolean false
1 =>
array (size=4)
0 => string 'http://localhost/wp/wp-content/uploads/2013/03/featured.jpg' (length=59)
1 => int 1584
2 => int 346
3 => boolean false
我的问题是,我怎么能循环遍历这个数组来生成一个只包含两个值如下一个新的数组:
My Question is that how can I loop through this array to generate a new array that contains only two values as following:
$result_array = array(0 => "http://localhost/wp/wp-content/uploads/2013/03/slider-area.jpg",
1 => "http://localhost/wp/wp-content/uploads/2013/03/featured.jpg");
我已经尝试了foreach循环,但无法获得所需的结果数组。我尝试了以下循环:
I have tried a foreach loop but could not get the required result array. I tried the following loop:
foreach ( $array as $key => $value ){
foreach ( $value as $item){
$result_array[] = $item;
}
任何帮助将是非常美联社preciated。
Any help will be highly appreciated.
推荐答案
您已经接近:
$result_array = array(); //Initialization is important.
foreach ($array as $value) {
$result_array[] = $value[0]; // $value[0] is the first element in the inner array.
}
这篇关于创建多维数组的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文