//not a short solution or a fast one but has some advantages:
//1. has some logic shared by GhostCat but in a interative way
//2. takes in consideration of multiple cases of A,B,C... in case you load your data from DB
//3. separates raw data from logic, easy to edit later and expand
$data = array(
'A' => array(
'variables' => array(
'x' => array(
10 => '<'
),
'y' => array(
2 => '<='
),
),
'function' => 'functionA',
),
'B' => array(
'variables' => array(
'x' => array(
50 => '<'
),
'y' => array(
2 => '>'
),
),
'function' => 'functionB',
),
'C' => array(
'variables' => array(
'x' => array(
250 => '<'
),
'y' => array(
50 => '<='
),
),
'function' => 'functionC',
),
);
//
foreach ($data[$product]['variables'] as $variable => $variable_data) {
foreach ($variable_data as $number => $operator) {
switch ($operator) {
case '<':
if (!($variable < $number)) {
myFailFunction();
}
break;
case '<=':
if (!($variable <= $number)) {
myFailFunction();
}
break;
case '>':
if (!($variable < $number)) {
myFailFunction();
}
break;
}
}
}
//if no fail was met run attached function
$func_name = $data[$product]['function'];
$func_name();
//it should run like this too
//$data[$product]['function']();