开发者

php associative array name?

开发者 https://www.devze.com 2023-01-02 09:33 出处:网络
Just trying to get the name of an assoc array; $test 开发者_JAVA百科= array(\'selected\' =>$selected, \'sectionList\'=>$sectionList, \'categoryList\'=>$categoryList);

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

精彩评论

暂无评论...
验证码 换一张
取 消