欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

循环体末尾的变量,还会从开始处检测、运行吗?

程序员文章站 2022-03-29 16:24:49
...
循环体末尾的变量,还会从开始处检测、运行吗?请达人示意。
/*
* If the taxonomy supports hierarchy and the term has a parent, make the slug unique
* by incorporating parent slugs.
*/
$parent_suffix = '';
if ( $needs_suffix && is_taxonomy_hierarchical( $term->taxonomy ) && ! empty( $term->parent ) ) {
$the_parent = $term->parent;
while ( ! empty($the_parent) ) { //AAAA
$parent_term = get_term($the_parent, $term->taxonomy);
if ( is_wp_error($parent_term) || empty($parent_term) )
break;
$parent_suffix .= '-' . $parent_term->slug;
if ( ! term_exists( $slug . $parent_suffix ) ) {
break;
}

if ( empty($parent_term->parent) )
break;
$the_parent = $parent_term->parent ;//至此,还会返回 AAAA 吗?
}
}


回复讨论(解决方案)

当然!因为判断循环是否终止,是在 AAAA 处

if ( is_wp_error($parent_term) || empty($parent_term) )
break;
$parent_suffix .= '-' . $parent_term->slug;
if ( ! term_exists( $slug . $parent_suffix ) ) {
break;
}

if ( empty($parent_term->parent) )
break;
$the_parent = $parent_term->parent;//至此,还会返回 AAAA 吗?
}

以上为一大块,没注意到。谢谢。

while ( ! empty($the_parent) ) {//AAAA
$parent_term = get_term($the_parent, $term->taxonomy);
if ( is_wp_error($parent_term) || empty($parent_term) )
break;
$parent_suffix .= '-' . $parent_term->slug;
if ( ! term_exists( $slug . $parent_suffix ) ) {
break;
}

if ( empty($parent_term->parent) )
break;
$the_parent = $parent_term->parent;//至此,还会返回 AAAA 吗?
}////为一大块,谢谢提醒。