views:

48

answers:

3

hello! Just trying to get the name of an assoc array;

$test = 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.

+1  A: 

Use the syntax foreach ($array as $key => $value) to also get the key when iterating an array.

Gumbo
thankyou! new it was something simple.best, Dan.
daniel Crabbe
+1  A: 

try using :

foreach ( $test as $name => $list )

dader51
A: 
$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>
        <? } ?>
    <? } ?>
aRagnis