我需要一些函数或解决方案来保存函数中变量的值,直到函数的下一次调用而不连接到MySQL。保存函数中变量的值直到下一次函数调用
function test($price){
if(isset($lastPrice)){
if($lastPrice>$price){
return true;
}
$lastPrice = $price;
}else{
$lastPrice = $price;
returne false;
}
}
$prices= array ('1' => '2000',
'2' => '2100',
'3' => '2100'
);
foreach($prices as $key = > $price){
if($this->test($price)){
echo 'got expensive';
}
}
在这段代码中,我需要$ lastPrice是保存,直到下一次测试()得到调用的foreach,...
你需要一个全局变量来做到这一点 – Misters