dqwr32867 2017-05-02 13:34
浏览 39
已采纳

从数组内的关联数组中删除键和值

I have a little bit chaotic problem... As you can see in code below, I have an array, which contains other arrays. It creates user navigation according to their roles. Navigation items are inherited and here is my problem. I need to set values for key 'dokumenty' in the lowest role EXPERT, than it shouldn't be visible for roles REPORTER and REFERENT and than again visible for EDITOR. So I am sharing EXPERT and REPORTER code, where I tried to remove values for 'dokumenty', but it threw me an error with array_merge()... I will be glad for any help, how to remove row with 'dokumenty' key. I think I shouldn't share whole return, because it's quite long.

     return array(
         AuthRoleEnum::EXPERT => array(
            'prehled' => array('order' => 1, 'href' => ':Dashboard:Default:default', 'label' => 'Prehled', 'ico' => 'fa fa-th-list'),
            'pozemky' => array('order' => 3, 'href' => '#', 'label' => 'Pozemky', 'ico' => 'fa fa-flag-o', 'nodes' => array(
                array('order' => 1, 'href' => ':Land:List:default', 'label' => 'Seznam pozemku', 'ico' => 'fa fa-flag-o'),
                array('order' => 2, 'href' => ':Land:List:selected', 'label' => 'Muj vyber', 'ico' => 'fa fa-flag-o'),
            )),
            'mapa' => array('order' => 4, 'href' => ':Map:Default:default', 'label' => 'Mapa', 'ico' => 'fa fa-globe'),
            'dokumenty' => array('order' => 8, 'href' => '#', 'label' => 'Dokumenty', 'ico' => 'fa fa-newspaper-o', 'nodes' => array(
                array('order' => 12, 'href' => ':ExpertReview:ContractsList:default', 'label' => 'Posudky', 'ico' => 'fa fa-folder'),
            )),
        ),
        AuthRoleEnum::REPORTER => array(
            'dokumenty' => null,
            'workflow' => array('order' => 20, 'href' => ':Construction:List:workflow', 'label' => 'Workflow', 'ico' => 'fa fa-cubes'),
        ),
        AuthRoleEnum::REFERENT => array(
            'stavby' => array('order' => 2, 'href' => ':Construction:List:default', 'label' => 'Stavby', 'ico' => 'fa fa-road', 'nodes' => [
                ['order' => 1, 'href' => ':Construction:List:default', 'label' => 'Seznam staveb', 'ico' => 'fa fa-road']
            ]),
            'kontakty' => array('order' => 9, 'href' => ':Contact:List:default', 'label' => 'Kontakty', 'ico' => 'fa fa-user', 'nodes' => []),
            'dokumenty' => array('order' => 8, 'href' => '#', 'label' => 'Dokumenty', 'ico' => 'fa fa-newspaper-o', 'nodes' => array(
                array('order' => 9, 'href' => ':Document:List:default', 'hrefArgs' => array('landId' => null), 'label' => 'Seznam dokumentu', 'ico' => 'fa fa-newspaper-o'),
            )),
        ),
        AuthRoleEnum::EDITOR => array(
            'alarmy' => array('order' => 5, 'href' => '#', 'label' => 'Alarmy', 'ico' => 'fa fa-bell-o', 'nodes' => array(
                array('order' => 6, 'href' => ':Alarm:List:default', 'label' => 'Seznam alarmu', 'ico' => 'fa fa-bell-o', 'class' => 'alarm-menu-field')
            )),
            'dokumenty' => array('order' => 8, 'href' => '#', 'label' => 'Dokumenty', 'ico' => 'fa fa-newspaper-o', 'nodes' => array(
                array('order' => 10, 'href' => ':InsertionCadastral:GenerateInsertion:list', 'label' => 'Pozadavky na vklad do KN', 'ico' => 'fa fa-cloud-upload'),
                array('order' => 11, 'href' => ':Document:GenerateDocx:firstStep', 'label' => 'Generovani dokumentu', 'ico' => 'fa fa-pencil-square', 'class' => 'show-in-modal'),
                array('order' => 12, 'href' => ':ExpertReview:ContractsList:default', 'label' => 'Posudky', 'ico' => 'fa fa-folder'),
            )),
            'fronta' => array('order' => 15, 'href' => ':Queue:List:default', 'label' => '', 'ico' => 'fa fa-circle', 'class' => 'queue-menu-field'),
            'pozemky' => array('order' => 3, 'href' => '#', 'label' => 'Pozemky', 'ico' => 'fa fa-flag-o', 'nodes' => array(
                array('order' => 3, 'href' => ':Land:Comment:list', 'label' => 'Parcely s poznamkou', 'ico' => 'fa fa-flag-o'),
                array('order' => 4, 'href' => ':BuildingObject:List:default', 'label' => '_T_MAIN_MENU_TITLE_BUILDING_OBJECT', 'ico' => 'fa fa-building')
            )),
        ),
        AuthRoleEnum::ADMIN => array(
            'stavby' => array('order' => 2, 'href' => ':Construction:List:default', 'label' => 'Stavby', 'ico' => 'fa fa-road', 'nodes' => [
                ['order' => 2, 'href' => ':Construction:UserActivity:default', 'label' => 'Aktivita uzivatelu', 'ico' => 'fa fa-user']
            ]),
            'system' => array('order' => 10, 'href' => '#', 'label' => 'System', 'ico' => 'fa fa-cog', 'nodes' => array(
                array('order' => 4, 'href' => ':Setting:UserConstruction:default', 'label' => 'Sprava opravneni uzivatelu a staveb', 'ico' => 'fa fa-building-o'),
                array('href' => ':Setting:User:default', 'label' => 'Uzivatelske ucty', 'ico' => 'fa fa-list')
            )),
            'alarmy' => array('order' => 5, 'href' => '#', 'label' => 'Alarmy', 'ico' => 'fa fa-bell-o', 'nodes' => array(
                array('order' => 7, 'href' => ':Alarm:Edit:add', 'label' => 'Pridani alarmu', 'ico' => 'fa fa-pencil-square', 'class' => 'show-in-modal')
            )),
        ),
        AuthRoleEnum::SUPERADMIN => array(
            'kontakty' => array('order' => 18, 'href' => '#', 'label' => 'Kontakty', 'ico' => 'fa fa-user', 'nodes' => array(
                array('href' => ':Contact:List:default', 'label' => 'Kontakty', 'ico' => 'fa fa-folder'),
                array('href' => ':ExpertReview:Contact:default', 'label' => 'Posudkari', 'ico' => 'fa fa-folder')
            )),
            'system' => array('order' => 11, 'href' => '#', 'label' => 'System', 'ico' => 'fa fa-list', 'nodes' => array(
                array('href' => ':Setting:Selection:default', 'label' => 'Ciselniky', 'ico' => 'fa fa-list'),
                array('href' => ':Setting:System:edit', 'label' => 'Zakladni parametry', 'ico' => 'fa fa-list', 'class' => 'show-in-modal', 'dataredirect' => 'false'),
                array('href' => ':Setting:ConstructionGeneratedSelections:default', 'label' => 'Sablony generovanych dokumentu', 'ico' => 'fa fa-list'),
                array('href' => ':Setting:ConstructionInsertedSelections:default', 'label' => 'Sablony vkladanych dokumentu', 'ico' => 'fa fa-list'),
                array('href' => ':Setting:WsUsers:default', 'label' => 'Uzivatele webovych sluzeb', 'ico' => 'fa fa-credit-card'),
                array('href' => ':Setting:UserLog:default', 'label' => 'Kompletni log', 'ico' => 'fa fa-h-square'),
                array('href' => 'changeDebugMode!', 'label' => $debugModeLabel, 'ico' => 'fa fa-gears'),
                array('href' => ':Setting:Changelog:list', 'label' => 'Changelog', 'ico' => 'fa fa-gears'),
            )),
        )
    );

Error while I try 'dokumenty' => null,:

array_merge(): Argument #1 is not an array search
  • 写回答

2条回答 默认 最新

  • douxiawei9318 2017-05-03 08:12
    关注

    Solved, I had to use shorthand for if and it works.

     'dokumenty' => (($userRole[0] == "EXPERT") ? (array('order' => 8, 'href' => '#', 'label' => 'Dokumenty', 'ico' => 'fa fa-newspaper-o', 'hidden' => 0, 'nodes' => array(
          array('order' => 12, 'href' => ':ExpertReview:ContractsList:default', 'label' => 'Posudky', 'ico' => 'fa fa-folder'),
          ))) : null),
      ),
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向