脚本宝典收集整理的这篇文章主要介绍了PHP相当于Javascript“with”范围语句,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
VAR a,x,y; var r = 10; wITh (Math) { a = PI * r * r; x = r * cos(PI); y = r * sin(PI / 2); }
代替
a = Math.PI * r * r; x = r * Math.cos(Math.PI); y = r * Math.sin(Math.PI / 2);
在最后一个例子中将是PHP,IE中的相同比例,在第二个代码示例中,Math是多余的.
class MyExampleClass { function example { for($i = 0; $i < count($this->Registers); $i++) { $r = "50"; $r .= $this->ZeroFill($this->numericOnly($this->Registers[$i]->Id)),15) . $this->ZeroFill($this->numericOnly($this->Registers[$i]->Inscription),25); $r .= $this->ZeroFill($this->Registers[$i]->model,2 ); $r .= $this->PadR($this->alpha($this->Registers[$i]->Date),10 ); $this->WriteRecord( $r); } }
在第三个例子中,我可以在$this-> Registers [$i]的语句中使用temp $var,但是如果所有的处理代码都变成了类Sanitize这样的类.
with (Sanitize) { $r .= ZeroFill(numericOnly($tmp),15); // are much more clear and using OO }
以上是脚本宝典为你收集整理的PHP相当于Javascript“with”范围语句全部内容,希望文章能够帮你解决PHP相当于Javascript“with”范围语句所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。