PHP - Angen help i fewnosod araeau mewn araeau Cysylltiol ar allweddi penodol

Iawn, felly mae gen i arae fel hynny:

$buttons = array(
    'home' => array(
        'title' => $txt['home'],
        'href' => $scripturl,
        'show' => true,
        'sub_buttons' => array(
        ),
        'is_last' => $context['right_to_left'],
    ),
    'help' => array(
        'title' => $txt['help'],
        'href' => $scripturl . '?action=help',
        'show' => true,
        'sub_buttons' => array(
        ),
    ),
    'search' => array(
        'title' => $txt['search'],
        'href' => $scripturl . '?action=search',
        'show' => $context['allow_search'],
        'sub_buttons' => array(
        ),
    ),
    'admin' => array(
        'title' => $txt['admin'],
        'href' => $scripturl . '?action=admin',
        'show' => $context['allow_admin'],
        'sub_buttons' => array(
            'featuresettings' => array(
                'title' => $txt['modSettings_title'],
                'href' => $scripturl . '?action=admin;area=featuresettings',
                'show' => allowedTo('admin_forum'),
            ),
            'packages' => array(
                'title' => $txt['package'],
                'href' => $scripturl . '?action=admin;area=packages',
                'show' => allowedTo('admin_forum'),
            ),
            'errorlog' => array(
                'title' => $txt['errlog'],
                'href' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc',
                'show' => allowedTo('admin_forum') && !empty($modSettings['enableErrorLogging']),
            ),
            'permissions' => array(
                'title' => $txt['edit_permissions'],
                'href' => $scripturl . '?action=admin;area=permissions',
                'show' => allowedTo('manage_permissions'),
                'is_last' => true,
            ),
        ),
    ),
    'moderate' => array(
        'title' => $txt['moderate'],
        'href' => $scripturl . '?action=moderate',
        'show' => $context['allow_moderation_center'],
        'sub_buttons' => array(
            'modlog' => array(
                'title' => $txt['modlog_view'],
                'href' => $scripturl . '?action=moderate;area=modlog',
                'show' => !empty($modSettings['modlog_enabled']) && !empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1',
            ),
            'poststopics' => array(
                'title' => $txt['mc_unapproved_poststopics'],
                'href' => $scripturl . '?action=moderate;area=postmod;sa=posts',
                'show' => $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']),
            ),
            'attachments' => array(
                'title' => $txt['mc_unapproved_attachments'],
                'href' => $scripturl . '?action=moderate;area=attachmod;sa=attachments',
                'show' => $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']),
            ),
            'reports' => array(
                'title' => $txt['mc_reported_posts'],
                'href' => $scripturl . '?action=moderate;area=reports',
                'show' => !empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1',
                'is_last' => true,
            ),
        ),
    ),
    'profile' => array(
        'title' => $txt['profile'],
        'href' => $scripturl . '?action=profile',
        'show' => $context['allow_edit_profile'],
        'sub_buttons' => array(
            'summary' => array(
                'title' => $txt['summary'],
                'href' => $scripturl . '?action=profile',
                'show' => true,
            ),
            'account' => array(
                'title' => $txt['account'],
                'href' => $scripturl . '?action=profile;area=account',
                'show' => allowedTo(array('profile_identity_any', 'profile_identity_own', 'manage_membergroups')),
            ),
            'profile' => array(
                'title' => $txt['forumprofile'],
                'href' => $scripturl . '?action=profile;area=forumprofile',
                'show' => allowedTo(array('profile_extra_any', 'profile_extra_own')),
                'is_last' => true,
            ),
        ),
    ),
    'pm' => array(
        'title' => $txt['pm_short'],
        'href' => $scripturl . '?action=pm',
        'show' => $context['allow_pm'],
        'sub_buttons' => array(
            'pm_read' => array(
                'title' => $txt['pm_menu_read'],
                'href' => $scripturl . '?action=pm',
                'show' => allowedTo('pm_read'),
            ),
            'pm_send' => array(
                'title' => $txt['pm_menu_send'],
                'href' => $scripturl . '?action=pm;sa=send',
                'show' => allowedTo('pm_send'),
                'is_last' => true,
            ),
        ),
    ),
    'calendar' => array(
        'title' => $txt['calendar'],
        'href' => $scripturl . '?action=calendar',
        'show' => $context['allow_calendar'],
        'sub_buttons' => array(
            'view' => array(
                'title' => $txt['calendar_menu'],
                'href' => $scripturl . '?action=calendar',
                'show' => allowedTo('calendar_post'),
            ),
            'post' => array(
                'title' => $txt['calendar_post_event'],
                'href' => $scripturl . '?action=calendar;sa=post',
                'show' => allowedTo('calendar_post'),
                'is_last' => true,
            ),
        ),
    ),
    'mlist' => array(
        'title' => $txt['members_title'],
        'href' => $scripturl . '?action=mlist',
        'show' => $context['allow_memberlist'],
        'sub_buttons' => array(
            'mlist_view' => array(
                'title' => $txt['mlist_menu_view'],
                'href' => $scripturl . '?action=mlist',
                'show' => true,
            ),
            'mlist_search' => array(
                'title' => $txt['mlist_search'],
                'href' => $scripturl . '?action=mlist;sa=search',
                'show' => true,
                'is_last' => true,
            ),
        ),
    ),
    'login' => array(
        'title' => $txt['login'],
        'href' => $scripturl . '?action=login',
        'show' => $user_info['is_guest'],
        'sub_buttons' => array(
        ),
    ),
    'register' => array(
        'title' => $txt['register'],
        'href' => $scripturl . '?action=register',
        'show' => $user_info['is_guest'],
        'sub_buttons' => array(
        ),
        'is_last' => !$context['right_to_left'],
    ),
    'logout' => array(
        'title' => $txt['logout'],
        'href' => $scripturl . '?action=logout;%1$s=%2$s',
        'show' => !$user_info['is_guest'],
        'sub_buttons' => array(
        ),
        'is_last' => !$context['right_to_left'],
    ),
);

Nawr rydw i eisiau gallu mewnosod arae ynddo, naill ai cyn neu ar ôl unrhyw un o'r allweddi yn yr arae uchod. Gall yr arae rydw i am ei mewnosod edrych fel hyn:

$new_menu_buttons['testing'] = array(
    'title' => $txt['testing'],
    'href' => $scripturl . '?action=testing',
    'show' => true,
    'target' => '_self',
    'active_button' => false,
);

Roedd rhywun yn argymell swyddogaethau i drin hyn a dulliau i'w defnyddio, ond nid wyf yn siŵr sut i wneud hyn, maent eisiau gwrthbwyso ar gyfer y swyddogaethau hyn hefyd. Dyma'r strwythur swyddogaeth yr argymhellodd rhywun y dylwn ei ddefnyddio ar gyfer hyn, na galw'r swyddogaethau hyn yn ôl yr angen:

function array_insert_before($array, $key, $new_array)
{
    // Splice array in two at key, keeping key on the right side
    // Append new value on the left tail
    // Glue both arrays into a new array
    // Return new array
}
function array_insert_after($array, $key, $new_array)
{
    // Symmetric with right & left switched
}

Felly , Rwyf am allu galw'r swyddogaethau fel hynny:

Os oes angen iddo fynd ar ôl yr allwedd, 'cartref' a bennir:

$menu_buttons = array_insert_after($buttons, 'home', $new_menu_buttons);

Os oes angen iddo fynd cyn yr allwedd, 'cartref' a bennir :

$menu_buttons = array_insert_before($buttons, 'home', $new_menu_buttons);

Yn y bôn, mae gwir angen help arnaf gyda'r swyddogaethau hyn, byddai unrhyw help yn wych.

A ddylwn i fod yn defnyddio array_splice neu array_slice ? A fyddai rhywun yn barod i fy nghychwyn i'r cyfeiriad cywir yma gyda rhywfaint o god gwirioneddol os gwelwch yn dda?

Diolch bois :)

6
задан Aziz Shaikh 28 June 2011 в 05:51
поделиться