我只是在学习PHP,我正在使用get\\u terms从CMS中获取一些文本描述,但我只想为我的woocommerce标记中的3个分配3个变量。我的代码运行得很好,但我只想了解是否有比使用if条件更好的方法通过$tag\\u descrip->name进行过滤。
这是我的代码:
<?php
$tag_descrip = get_terms( \'product_tag\', \'orderby=count&hide_empty=0\' );
$count = count($tag_descrip);
if ( $count > 0 ){
foreach ( $tag_descrip as $tag_descrip ) {
if($tag_descrip->name == "parfum_bestof")
{$title_new1 = $tag_descrip->description ;}
if($tag_descrip->name == "tshirt_bestof")
{$title_new2 = $tag_descrip->description ;}
if($tag_descrip->name == "child_bestof")
{$title_new3 = $tag_descrip->description ;}
}
}
?>
谢谢