php associative array name?
Just trying to get the name of an assoc array;
$test 开发者_JAVA百科= array('selected' =>$selected, 'sectionList'=>$sectionList, 'categoryList'=>$categoryList);
<? foreach($test as $list) { ?>
<h3><?=$list?>, <?=$list[id]?>, <?=$list['name']?>, <?=$list['value']?></h3>
<? } ?>
but either get 'Array' or nothing?! I can see the name when i print_r($test);
Do you think this is possible? Thanks in advance, D.
Use the syntax foreach ($array as $key => $value)
to also get the key when iterating an array.
try using :
foreach ( $test as $name => $list )
$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>
<? } ?>
<? } ?>
精彩评论