I am writing a PHP library in which i want to create a dynamic string which execute in a IF statement. Below is the scenario.
Controller Code
$config = [
'option' => [
'exclude' => [
'system_account' => 1,
'postable_account' => 0
]
]
];
$drop_down_generator = new DropDownOptionsGenerator($config);
$drop_down_generator->generateMarkup($result);
Library Code
$exclude = $this->config['option']['exclude'];
$exclude_condition = '';
if (!empty($exclude)) {
//Generating IF Statemnet Condition String. Multiple Condtions can be sent from the Controller
foreach ($exclude as $key => $condition_value) {
$exclude_condition .= (empty($exclude_condition)) ? '$row->' . $key . ' == "' . $condition_value . '"' : ' && $row->' . $key . ' == "' . $condition_value . '"';
}
}
foreach ($data as $key => $row) {
// Here is the Problem, As you can see below the output of the $exclude_condition variable containing $row variable
// which is not executing in the "IF" statement
// Output of $exclude_statement => $row->system_account == "1" && $row->postable_account == "0"
if (! $exclude_condition) {
$output .= sprintf($this->option_format, $row->$value, '', $row->$label);
}
}
In short Words: How can i execute string which contains multiple variables in IF Condition ?
OR
Suggest me another best solution to solve my Problem.
Aucun commentaire:
Enregistrer un commentaire