如何优化下面的三行代码


How to optimize the following three lines of code

如果有一个函数(在PHP中,尽管在这种情况下无关紧要)需要返回布尔变量的值(此时可能为真或假),然后将相同的变量设置为假,因为它的值已经报告。代码看起来像这样:

$return_value = $report_boolean;
$report_boolean = false;
return $return_value;

基本上我想返回$report_boolean中包含的任何内容,然后确保在此之后将其设置为false。有没有一种方法可以在一行中做到这一点,而不使用额外的"保持跟踪"变量?

如果您在return调用上执行赋值,并确保它运行(注意延迟求值):

return $return_value && (($return_value = false)||true)