php关联数组名称?

时间:2010-06-01 16:39:55

标签: php associative-array

只是想获取一个关联数组的名称;

$test = array('selected' =>$selected, 'sectionList'=>$sectionList, 'categoryList'=>$categoryList);
<? foreach($test as $list) { ?>
<h3><?=$list?>, <?=$list[id]?>, <?=$list['name']?>, <?=$list['value']?></h3>
<? } ?>

但要么得到'数组'还是什么都没有?!我可以在print_r($ test);

时看到这个名字

你认为这是可能的吗?在此先感谢,D。

3 个答案:

答案 0 :(得分:4)

使用语法foreach ($array as $key => $value)在迭代数组时也获取密钥。

答案 1 :(得分:1)

尝试使用:

foreach($ test as $ name =&gt; $ list)

答案 2 :(得分:0)

$test = array('selected' =>$selected, 'sectionList'=>$sectionList, 'categoryList'=>$categoryList);
    <? foreach($test as $key => $list) { ?>
        <? foreach($list as $list2) { ?>
            <h3><?=$key?>, <?=$list2[id]?>, <?=$list2['name']?>, <?=$list2['value']?></h3>
        <? } ?>
    <? } ?>