Using an If-else within an array

后端 未结 10 1901
滥情空心
滥情空心 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:15

    Yes, this is possible using a certain shorthand:

     array(
                 ($LibraryStatus ? array("wLibrary" => array("title"   => "XMBC Library",
                                                             "display" => "")) : false),
                 ($ControlStatus ? array("wControl" => array("title"   => "Control",
                                                             "display" => "")) : false)));
    
    print_r($arrLayout);
    
    ?>
    

    It works like this:

    if($a == $b){ echo 'a'; }else{ echo 'b'; }
    

    is equal to

    echo $a == $b ? 'a' : 'b';
    

    If you use this shorthand it will always return the output, so you can put it between brackets and put it inbetween the array.

    http://codepad.org/cxp0M0oL

    But for this exact situation there are other solutions as well.

提交回复
热议问题