php If 语句基于 dirTree 的级别



我有一个反映网站结构的数组。我正在尝试根据我所处的级别执行 if 语句:

运行简单测试:

<?php if ($dirTree[0]){echo "level1";}?>
<?php if ($dirTree[1]){echo "level2";}?>

正确检查并返回电平,但由于$dirTree[1] 检查中存在 $dirTree[0],因此两个级别都会回显出来。

无论如何,运行 if 语句来仅查明活动级别吗?

2级$dirTree的内容(1级和2级相呼应):

Array
(
    [0] => CategoryItem Object
        (
            [id] => 200139
            [isCategory] => 1
            [conceptID] => 200139
            [preferred] => 1
            [obsolete] => 
            [type] => 
            [addedInVersion] => 0.05
            [lastUpdatedInVersion] => 0.05
            [AToZ] => 
            [name] => Council tax
            [scopeNotes] => 
            [historyNotes] => Added in 0.05
            [broaderItems] => Array
                (
                )
            [narrowerItems] => Array
                (
                    [0] => ReferenceItem Object
                        (
                            [id] => 200180
                            [default] => 1
                            [type] => BROADERITEM
                        )
                    [1] => ReferenceItem Object
                        (
                            [id] => 200181
                            [default] => 1
                            [type] => BROADERITEM
                        )
                    [2] => ReferenceItem Object
                        (
                            [id] => 200182
                            [default] => 1
                            [type] => BROADERITEM
                        )
                    [3] => ReferenceItem Object
                        (
                            [id] => 200248
                            [default] => 1
                            [type] => BROADERITEM
                        )
                    [4] => ReferenceItem Object
                        (
                            [id] => 200249
                            [default] => 1
                            [type] => BROADERITEM
                        )
                    [5] => ReferenceItem Object
                        (
                            [id] => 200250
                            [default] => 1
                            [type] => BROADERITEM
                        )
                    [6] => ReferenceItem Object
                        (
                            [id] => 200251
                            [default] => 1
                            [type] => BROADERITEM
                        )
                )
            [relatedItems] => Array
                (
                )
            [useItem] => -1
            [shortcut] => 
        )
    [1] => CategoryItem Object
        (
            [id] => 200181
            [isCategory] => 1
            [conceptID] => 200139
            [preferred] => 1
            [obsolete] => 
            [type] => 
            [addedInVersion] => 0.05
            [lastUpdatedInVersion] => 0.05
            [AToZ] => 
            [name] => Money off your bill
            [scopeNotes] => 
            [historyNotes] => Added in 0.05
            [broaderItems] => Array
                (
                    [0] => ReferenceItem Object
                        (
                            [id] => 200139
                            [default] => 1
                            [type] => BROADERITEM
                        )
                )
            [narrowerItems] => Array
                (
                )
            [relatedItems] => Array
                (
                )
            [useItem] => -1
            [shortcut] => 
        )
)

由于数组中的最后一个元素始终是活动级别,因此活动级别应与数组的大小相同:

$active = count($dirTree);

相关内容

  • 没有找到相关文章

最新更新