循环遍历 PHP 中的几个函数
基本上我想实现连续执行 5-10 个函数的功能(就像通常一样)。但是,如果收到特定返回,我希望脚本返回几个步骤(例如从第 5 步回到第 3 步)并进一步继续(如 4、5、6、7、8、9、10)。示例:
<?
function_1st();
function_2nd();
function_3rd();
function_4th();
$a = function_5th();
if($a == '3') //continue from 3rd further;
function_6th();
function_7th();
?>
在本例中,它应该是 1,2,3,4,5,3,4,5,6,7,8,9,10。 在此使用面向对象编程(类)会更好吗?
基本上我只需要建议,如何以正确的方式做到这一点:)
问候, 乔纳斯
Basically I want to achieve such functionality that 5-10 functions are executed in a row (like normally). However, I want the script to go back several steps back (ex. from 5th back to 3rd) and continue further (like 4,5,6,7,8,9,10), if specific return is received. Example:
<?
function_1st();
function_2nd();
function_3rd();
function_4th();
$a = function_5th();
if($a == '3') //continue from 3rd further;
function_6th();
function_7th();
?>
Like in this case it should be 1,2,3,4,5,3,4,5,6,7,8,9,10.
Would it be better to use object orientated programming (class) in this?
Basically I need only advice, how to make it like this in a proper waY :)
Regards,
Jonas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将所有函数包装在一个开关中,如下所示:
wrap all the functions in a switch something like:
您可以将函数调用基于上一个函数返回
示例:
You could base the function calls on the previous function return
Example:
使用“变量函数”或“call_user_func()函数”。我没有时间解释,请谷歌搜索关键字。
Use "variable functions" or "call_user_func() function". I don't have time to explain it, please google that keywords.
为什么需要这样做?您是说,如果在调用 function_5() 之后调用 function_3() ,那么 $a 上的结果会有所不同,然后它将通过 function_5() 的检查?
您可能需要重新思考您的总体逻辑。
顺便说一句,不要使用短标签。写出
Why would you need to do this? Are you saying that the results on $a will be different if function_3() is called on it after function_5() has been called on it and then it will pass the check on function_5() ?
You may need to rethink your logic in general.
By the way, don't use short tags. Write out