php 基于 dirTree 级别的 If 语句
php If statement based on level of dirTree
我有一个反映站点结构的数组。我正在尝试根据我所在的级别执行 if 语句:
运行 简单测试:
<?php if ($dirTree[0]){echo "level1";}?>
<?php if ($dirTree[1]){echo "level2";}?>
检查正确并且 returns 级别,但是由于 $dirTree[0] 出现在 $dirTree[1] 上,检查两个级别都被呼应了。
是否有 运行 if 语句仅用于确定活动级别?
第 2 层 $dirTree 的内容(level1 和 level2 相呼应):
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);
我有一个反映站点结构的数组。我正在尝试根据我所在的级别执行 if 语句:
运行 简单测试:
<?php if ($dirTree[0]){echo "level1";}?>
<?php if ($dirTree[1]){echo "level2";}?>
检查正确并且 returns 级别,但是由于 $dirTree[0] 出现在 $dirTree[1] 上,检查两个级别都被呼应了。
是否有 运行 if 语句仅用于确定活动级别?
第 2 层 $dirTree 的内容(level1 和 level2 相呼应):
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);