PHP:如何动态更改“if”条件顺序
情况是这样的:有一个连续的循环,更新一些值。然后脚本检查某些条件。 (简化的)代码:
<?php
set_time_limit(0);
// etc
while(1==1)
{
$a = getFromDatabase('a'); // function to get value of A
$b = getFromDatabase('b'); // function to get value of B
$c = getFromDatabase('c'); // function to get value of C
$d = getFromDatabase('d'); // function to get value of D
if($a >= 12 && time() <= $b && ($d === false || $d <= time()))
{
include 'pages/'.$a.'.php';
}
if($b <= 3 && time() >= $d && ($c === false || $c <= time()))
{
include 'pages/'.$b.'.php';
}
}
我的问题是:如何动态更改这些 IF 语句的顺序?
重要提示
$order = array('b','a'); // first b then a
:if 条件确实是动态的。所以不存在真正的模式(上面的例子是简化的,所以不是完整的条件)
The situation is like this: there is a continuous loop, that updates some values. Then the script checks certain conditions. The (simplified) code:
<?php
set_time_limit(0);
// etc
while(1==1)
{
$a = getFromDatabase('a'); // function to get value of A
$b = getFromDatabase('b'); // function to get value of B
$c = getFromDatabase('c'); // function to get value of C
$d = getFromDatabase('d'); // function to get value of D
if($a >= 12 && time() <= $b && ($d === false || $d <= time()))
{
include 'pages/'.$a.'.php';
}
if($b <= 3 && time() >= $d && ($c === false || $c <= time()))
{
include 'pages/'.$b.'.php';
}
}
My question is: how can I change the order of these IF-statements dynamically?
Like
$order = array('b','a'); // first b then a
Important: the if conditions are really dynamic. So there is no real pattern (the example above is simplified, so not the full conditions)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将它们放入函数中,然后仅存储函数的名称并依次遍历每个函数。
Put them in functions, then just store the name of the functions and go through each in turn.
不确定这是否是您想要的,但您可以将
if
放入函数中:Not sure if that's what you want, but you can put
if
in functions: