在php中从较大的关联数组中提取数组

时间:2015-05-03 21:33:51

标签: php arrays multidimensional-array associative-array

我在一个关联数组中存储了许多数组,并为键值分配了简单的数字计数。

如何从关联数组中提取其中一个数组?

我的阵列:

$arr = array(
        1 => array("ask","bat","cod","dig","egg","fur","gap","hay","ice","jar","kin","lee"), 
        2 => array("add","big","cap","day","eye","fat","gel","hop","ink","jog","key","law"),   
        3 => array("axe","bin","cel","don","eat","fig","gig","hut","ion","jin","kid","lip")
    );

我想在$arr_chosen中存储索引为2的数组,这样做的语法是什么?

2 个答案:

答案 0 :(得分:2)

$arr = array(
        1 => array("ask","bat","cod","dig","egg","fur","gap","hay","ice","jar","kin","lee"), 
        2 => array("add","big","cap","day","eye","fat","gel","hop","ink","jog","key","law"),   
        3 => array("axe","bin","cel","don","eat","fig","gig","hut","ion","jin","kid","lip")
    );
$arr_chosen = $arr[2];

答案 1 :(得分:1)

您可以通过

提取数组
$arr_chosen = $arr[2]