卸下外部阵列: [英] Removing an outer array:
本文介绍了卸下外部阵列:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果数组中有一个数组,如何删除外部数组:
IF you have an array within an array, how can you remove the outer array:
$outer_array = array(0 => array(
'key1' => 'value1',
'key2' => 'value2'
));
print_r($ outer_array)产生:
print_r($outer_array) produces:
Array
(
[0] => Array
(
[key1] => value1
[key2] => value2
)
)
是否有内置在php中的函数,所以您可以使用:
Is there a function built into php so you are left with:
Array
(
[key1] => value1
[key2] => value2
)
推荐答案
您可以轻松地做到:
$new_array = $outer_array[0];
print_r($new_array);
结果:
Array
(
[key1] => value1
[key2] => value2
)
注意:正如@netcoder指出的那样,要使其同时适用于数字索引和字符串索引,您可以执行以下操作:
Note: As pointed out by @netcoder, to make it work for both numeric and string indexes, you can do:
$new_array = $outer_array[0];
$new_array = reset($out_arr);
这篇关于卸下外部阵列:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文