I am trying to build an if statement that is dynamically coded based on the values submitted by the users that visit the site. The if statement may have between 1 and 9 conditions to test (depending on user input), and XML values (from an XML document) will be displayed based on the if statement.
The potential if statement conditions are inserted in the $if_statement variable, like this:
$keyword = trim($_GET["Keyword"]);
if (!empty($keyword)) {
$if_statement = ($keyword == $Product->keyword);
}
$shopByStore = $_GET["store"];
if (!empty($shopByStore)) {
$if_statement = ($if_statement && $shopByStore == $Product->store);
}
// plus 7 more GET methods retrieving potential user input for the $if_statement variable.
However nothing is being displayed in the foreach loop below when using the dynamically coded if statement:
$XMLproducts = simplexml_load_file("products.xml");
foreach($XMLproducts->product as $Product) {
if ($if_statement) { // the problem lies here, because results ARE displayed when this if statement is removed
echo $Product->name;
}}
Any advice? Or is there a better way to dynamically code an if statement?