Good day. I would like to know if you can somehow implement the following:
There is an array with parts of the conditions that must be met.
$clauses=array( array( 'clause_name' => 'ext_dna_status', 'clause_sign' => '==', 'clause_value' => 0 ), array( 'clause_name' => 'end_date', 'clause_sign' => '>=', 'clause_value' => '2017-07-20' ) ); This array will be passed to the function (not yet written), which will have to check that all the conditions described in the array are met in the array of other data. A separate variable of the function is transferred to separate the parts of the conditions - and, or. Universality from the function is not required - it is designed to simply reduce the number of the same type of code.
For example, a function receives an array with data (below) and a separator at the input. Those. in fact, for each part of the array with data, you need to check each condition from the array with conditions - (I did not translate dates for clarity in unixtime) if ($ext_dna_status==1 and $end_date>=2017-07-20) .
$in=array( array( 'ext_dna_status' => 0, 'end_date' => '2017-07-20' ), array( 'ext_dna_status' => 1, 'end_date' => '2017-07-20' ), array( 'ext_dna_status' => 0, 'end_date' => '2017-07-25' ) ); The question is how to glue together parts of the conditions from the array so that they "work"? You can iterate over all elements of an array with conditions and change the value of a flag variable if the condition is met, for example. But how can parts of a condition be transformed into this very condition? Those. $clause=$clauses[0]['clause_name'].$clauses[0]['clause_sign'].$clauses[0]['clause_value']; treat as a condition ?
clause_sign(inswitch, for example) and compare the contents of['clause_value']and the element from$inin the corresponding branch of theswitch. - Vismaneval()function php.net/manual/ru/function.eval.php but it is not recommended to use it. - Visman$clausesarray. If interested =) - Andrey Mindubaev