2010-06-01 66 views
1

試圖獲取assoc數組的名稱;php關聯數組名?

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

但要麼'數組'或什麼都沒有?!我可以看到名稱,當我print_r($測試);

你認爲這是可能的嗎?在此先感謝,D.

回答

4

使用語法foreach ($array as $key => $value)也可以在迭代數組時獲得密鑰。

+0

三江源!新的它是簡單的。丹,最好, 最好。 – v3nt 2010-06-01 16:55:47

1

嘗試使用:

的foreach($測試爲$名=> $列表)

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> 
     <? } ?> 
    <? } ?>