计算函数回显语句的次数
我有一个调用其他两个函数的函数:
class myClass{
function myFunc(){
for($i=0;$i<500;$i++){
$this->func1();
$this->func2();
}
}
function func1(){
// Does some stuff
// echos statements, and can vary the amount of echoed statements
while($something == true)
echo "This is from func1, and may echo 0-1000 times";
}
function func2(){
// Does some stuff
// echos statements, and can vary the amount of echoed statements
while($something == true)
echo "This is from func2, and may echo 0-1000 times";
}
}
我想做的是找到一种方法,可以获取函数回显某些内容的总次数,并获取该信息以显示在 myFunc() 中。我写了一个计数函数,但它没有按照我预期的方式工作。
有什么建议吗?
I have a function that calls two other functions:
class myClass{
function myFunc(){
for($i=0;$i<500;$i++){
$this->func1();
$this->func2();
}
}
function func1(){
// Does some stuff
// echos statements, and can vary the amount of echoed statements
while($something == true)
echo "This is from func1, and may echo 0-1000 times";
}
function func2(){
// Does some stuff
// echos statements, and can vary the amount of echoed statements
while($something == true)
echo "This is from func2, and may echo 0-1000 times";
}
}
What I'd like to do is figure out a way that I can get the total times the functions have echo'd something and get that info to display in myFunc(). I wrote a count function, but it didn't work out the way I had expected.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一种方法:
或者更好的方法:
Here's one way:
or a better way:
为什么不让函数返回回显计数:
然后在 myFunc 中,您可以累积它们:
Why not have the functions return the echo count:
Then in myFunc, you can accumulate them: