我有一个名为 $best_cats
global $best_cats;
$best_cats = array(8,31,51,102,217,218);
现在我需要检查当前的猫是否在数组内,并且如果当前的猫是父猫。
我正在尝试这种方法,但不起作用。我做错了什么以及我该怎么做?
<?php
$this_category = get_category($cat);
$cat_id = $this_category->cat_ID;
if (in_array($cat_id, $best_cats) && ($this_category->category_parent == 0 )) { ?>
//category is inside of the array and is a parent cat
<?php } else { ?>
//category is not inside the array and It's not a parent either
<?php } ?>
最佳答案
看起来你忘记了global
<?php
global $best_cats;
$this_category = get_category($cat);
$cat_id = $this_category->cat_ID;
if (in_array($cat_id, $best_cats) && ($this_category->category_parent == 0 )) {
//category is inside of the array and is a parent cat
} else {
//category is not inside the array and It's not a parent either
}
关于php - 如何检查当前猫是否在数组内并且 IF 是父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39851446/