I would like to build an IF statement in PHP using some options that are coming from the Database.
Let's say I get an array like this from the DB:
$db = [
'number1' => [
'<= 5',
'&&'
],
'number2' => [
'> 200',
'&&'
],
'number3' => [
'= 1',
'||'
],
'number3' => [
'= 2',
'||'
],
];
I'd like to translate it into this:
if ($data['number1'] <= 5 &&
$data['number2'] > 200 &&
($data['number3'] == 1 ||
$data['number3'] == 2
)) {
// do something
}
Of course, I'd start it by doing a foreach and putting the KEYs of the array into the $data[''] array. However, I'm pretty unsure how can I put the logical operators and everything else in place.
Can anyone give me an idea please?
andandorlogic, what if you would like brackets to sayx and (y or z).number3).