PHP: How to change “if”-condition order dynamically

The situation is like this: there is a continuous loop, that updates some values. Then the script checks certain conditions. The (simplified) code:

// etc
    $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?


$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)


Put them in functions, then just store the name of the functions and go through each in turn.

function func1($a, $b, $c, $d)
  if (...)
    return $a
  return false;

function func2($a, $b, $c, $d)

$funcs = Array('func1', 'func2');


foreach($funcs as $func)
  if ($page = $func($a, $b, $c, $d))
    include "pages/$page.php"

Need Your Help

Problem With Python Sockets: How To Get Reliably POSTed data whatever the browser?

javascript python sockets comet

I wrote small Python+Ajax programs (listed at the end) with socket module to study the COMET concept of asynchronous communications.

How many number of primitive operations does a 16, 32 or a 64-bit processor execute to perform logical right shift of an N-bit Binary number?

algorithm cryptography bit-shift polynomial-math ecdsa

Recently,I have been trying to understand how the Binary Extended Euclidean Algorithm works at the processor level. This question is all about finding an Inverse element in GF(2^m) with polynomial ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.