$price=123;$price1=124;$symbol=">";//可能是
2 回答
慕的地8271018
TA贡献1796条经验 获得超4个赞
functioncompare($a,$b,callable$compare){return$compare($a,$b);}functionmore($a,$b){return$a>$b;}functionless($a,$b){return$a<$b;}functionequal($a,$b){return$a==$b;}var_dump(compare(123,124,'more'));var_dump(compare(123,124,'less'));var_dump(compare(123,124,'equal'));var_dump(compare(123,123,'equal'));简化版functioncompare($a,$b,$symbol){$compare=['>'=>function($a,$b){return$a>$b;},'<'=>function($a,$b){return$a<$b;},'='=>function($a,$b){return$a==$b;}];return$compare[$symbol]($a,$b);}var_dump(compare(123,124,'>'));var_dump(compare(123,124,'<'));var_dump(compare(123,124,'='));var_dump(compare(123,123,'='));
忽然笑
TA贡献1806条经验 获得超5个赞
肯定是不可以的建议写一个方法,传递这三个参数,然后内部判断functionaaa($symbol,$prcie,$price1){if($symbol=='='){if($price1==$price){returntrue}else{returnfalse}}elseif($symbol=='>'){if($price1>$price){returntrue}else{returnfalse}}elseif($symbol=='<'){if($price1<$price){returntrue}else{returnfalse}}}
添加回答
举报
0/150
提交
取消