我一直在查看 wordpress 的核心文件并偶然发现了这段代码,我注意到它在变量名之前和 = 之后有一个 & 符号。
我试过搜索这个并从PHP 手册中发现它并没有很好地解释它,或者我看错了!我还看到它用于在使用它的方法之外修改变量,但是,这就是变量的用途,要修改所以如果这是正确的,人们将如何使用它?
function _make_cat_compat( &$category ) {
if ( is_object( $category ) ) {
$category->cat_ID = &$category->term_id;
$category->category_count = &$category->count;
$category->category_description = &$category->description;
$category->cat_name = &$category->name;
$category->category_nicename = &$category->slug;
$category->category_parent = &$category->parent;
} elseif ( is_array( $category ) && isset( $category['term_id'] ) ) {
$category['cat_ID'] = &$category['term_id'];
$category['category_count'] = &$category['count'];
$category['category_description'] = &$category['description'];
$category['cat_name'] = &$category['name'];
$category['category_nicename'] = &$category['slug'];
$category['category_parent'] = &$category['parent'];
}
}