1

我一直在寻找如何做到这一点,有点难过。我的数组如下:

$returndata->setup_array = array(
            'General'       =>  array(
                    'Main Details'          => 'setup/maindets',
                    'Directories'           => 'directories',
                    'Extension Allocation'  => 'xtnallo',
                    'List Holidays'         => 'setup/holidays',
                    'List Group VM'         => 'groupvm',
                    'Conference Rooms'      => 'confroom'
                    ),
            'Offices'       =>  array(
                    'List Offices'          => 'iptoffices'
                    ),
            'Users'         =>  array(
                    'List Users'            => 'iptusers'
                    ),
            'Phones'        =>  array(
                    'List Phones'           => 'iptphones'
                    ),
            );

但是,我有 1 项在特定条件下(由用户会话触发)需要添加到通用数组的列表中。该部分是'View Details => setup/viewdetails'. 我已经尝试过数组推送(可能不正确),但这会将项目作为另一个数组添加到主数组的末尾。

我希望/需要它像这样工作:

$returndata->setup_array = array(
        'General'       =>  array(
                 $viewdets
                'Main Details'          => 'setup/maindets',
                'Directories'           => 'directories',
                'Extension Allocation'  => 'xtnallo',
                'List Holidays'         => 'setup/holidays',
                'List Group VM'         => 'groupvm',
                'Conference Rooms'      => 'confroom'
                ),
        'Offices'       =>  array(
                'List Offices'          => 'iptoffices'
                ),
        'Users'         =>  array(
                'List Users'            => 'iptusers'
                ),
        'Phones'        =>  array(
                'List Phones'           => 'iptphones'
                ),
        );

$viewdets = "'View Details'         => 'setup/viewdetails'";

并且仍然被解释为用作菜单的功能数组。

4

3 回答 3

2
$returndata->setup_array['General']['View Details'] = 'setup/viewdetails'

干杯瑞克!

于 2013-05-10T15:48:08.317 回答
0

您可以使用ArrayObject将数组作为参考:

$a  = new ArrayObject();

$b = array(
    "a" => $a
);

$a[] = "foo";
print_r($b);
于 2013-05-10T15:45:46.767 回答
0

你尝试调用array_push()什么?你有没有尝试过

array_push($returndata->setup_array['General'], $viewdets);

您需要将变量添加到您希望它存在的数组的特定深度。在这里查看array_push,还有一个简短的语言语法可以避免函数调用:

$returndata->setup_array['General'][] = $viewdets;
于 2013-05-10T15:50:46.373 回答