Using an If-else within an array

后端 未结 10 1943
滥情空心
滥情空心 2020-12-11 04:45

Hi guys I have no idea if this is possible or if there is another way of doing it but any help would be appreciated. What I\'m trying to do is turn off arrays individually.

10条回答
  •  一向
    一向 (楼主)
    2020-12-11 05:22

    What you are suggesting is not possible. You would need to add the variables base on the if/else conditional after you have made the array.

    For example:

    $arrLayout = array();
    
    if($LibraryStatus) {
        $arrLayout['section1'] = array("wLibrary" => array(
                "title" => "XBMC Library",
                "display" => ""
            ));
    }
    

    This still rather untidy because of your array structure, I'd try eliminating some keys if you can, for example do you need section1? You could just let PHP add a numerical key by doing $arrLayout[] = array(..), which create a new 'row' in the array which you can still loop through.

提交回复
热议问题