循环遍历Smarty中的多维数组

时间:2010-10-22 12:54:16

标签: multidimensional-array for-loop smarty

我在PHP中生成了一个多维数组:

array(
            'Requirements' => array(
                'export_requirements' => array('value'=> 1, 'label'=> 'Export'),
                'add_requirements' => array('value'=> 2, 'label'=> 'Add'),
                'add_private_requirements' => array('value'=> 4, 'label'=> 'Add Private Requirements'),
                'log_activity' => array('value'=> 8, 'label'=> 'Log Activity / Schedule Event'),
                'edit_activity' => array('value'=> 16, 'label'=> 'Edit Activity'),
                'delete_activity' => array('value'=> 32, 'label'=> 'Delete Activity'),
                'edit_requirements' => array('value'=> 64, 'label'=> 'Edit Requirements'),
                'edit_requirements_private' => array('value'=> 128, 'label'=> 'Edit Private Requirements'),
            ),
            'Resources' => array(
                'export_resources' => array('value'=> 1, 'label'=> 'Export'),
                'add_resources' => array('value'=> 2, 'label'=> 'Add'),
                'add_private_resources' => array('value'=> 4, 'label'=> 'Add Private Resources'),
                'log_activity' => array('value'=> 8, 'label'=> 'Log Activity / Schedule Event'),
                'edit_activity' => array('value'=> 16, 'label'=> 'Edit Activity'),
                'delete_activity' => array('value'=> 32, 'label'=> 'Delete Activity'),
                'edit_resources' => array('value'=> 64, 'label'=> 'Edit Resources'),
                'edit_resources_private' => array('value'=> 128, 'label'=> 'Edit Private Resources'),
            ),
            'Prospects' => array(
                'export_prospects' => array('value'=> 1, 'label'=> 'Export'),
                'add_prospects' => array('value'=> 2, 'label'=> 'Add'),
                'show_nsa' => array('value'=> 4, 'label'=> 'Show NSA Details'),
                'edit_prospects' => array('value'=> 8, 'label'=> 'Edit'),
                'log_activity' => array('value'=> 16, 'label'=> 'Log Activity / Schedule Event'),
                'edit_activity' => array('value'=> 32, 'label'=> 'Edit Activity'),
                'delete_activity' => array('value'=> 64, 'label'=> 'Delete Activity'),
            ),
            'Contacts' => array(
                'export_contacts' => array('value'=> 1, 'label'=> 'Export'),
                'add_contacts' => array('value'=> 2, 'label'=> 'Add'),
                'edit_contacts' => array('value'=> 4, 'label'=> 'Edit'),
                'log_activity' => array('value'=> 8, 'label'=> 'Log Activity / Schedule Event'),
                'edit_activity' => array('value'=> 16, 'label'=> 'Edit Activity'),
                'delete_activity' => array('value'=> 32, 'label'=> 'Delete Activity'),
            ),
            'Clients' => array(
                'export_clients' => array('value'=> 1, 'label'=> 'Export'),
                'add_clients' => array('value'=> 2, 'label'=> 'Add'),
                'show_caution_note' => array('value'=> 4, 'label'=> 'Show Caution Note'),
                'show_nsa_msa' => array('value'=> 8, 'label'=> 'Show NSA and MSA Details'),
                'edit_dormant_caution_caution_notes' => array('value'=> 16, 'label'=> 'Edit Dormant, Caution, Caution Notes'),
                'log_activity' => array('value'=> 32, 'label'=> 'Log Activity'),
                'edit_activity' => array('value'=> 64, 'label'=> 'Edit Activity'),
                'delete_activity' => array('value'=> 128, 'label'=> 'Delete Activity'),
            ),
            'Reports' => array(
                'view' => array('value'=> 1, 'label'=> 'View'),
            ),
            'Settings' => array(
                'administration' => array('value'=> 1, 'label'=> 'Administration'),
                'view_data_item_history' => array('value'=> 2, 'label'=> 'View Data Item History'),
                'assign_group_permissions' => array('value'=> 4, 'label'=> 'Assign Group Permissions'),
                'manage_users' => array('value'=> 8, 'label'=> 'Manage Users'),
                'assign_user_permissions' => array('value'=> 16, 'label'=> 'Assign User Permission'),
                'manage_roles' => array('value'=> 32, 'label'=> 'Manage Roles'),
                'assign_role_permission' => array('value'=> 64, 'label'=> 'Assign Role Permission'),
            ),
        );

有没有办法使用Smarty循环使用?

我到目前为止:

{foreach from=$all_perms  key=k item=v}
            <table width="100%" border="0" cellspacing="0" cellpadding="0"  class="detail view">
                <tr>
                <th colspan='4' align="left" width="100%" valign="top"><h4><slot>{$k}</slot></h4></th>
                </tr>
                {foreach from=$all_perms  key=k item=v} {% I'm stuck at this for loop %}
                    <tr>
                        <td width="15%" valign="top" scope="row">
                            <slot>{$k}:</slot>
                        </td>
                        <td width="85%" valign="top">
                            <slot>Allow</slot>
                        </td>
                    </tr>
                {/foreach}
            </table>
        {/foreach}

1 个答案:

答案 0 :(得分:2)

尝试更改第二个循环:

{foreach from=$v  key=key item=value}