1

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.

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

try using :

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.