我想用逻辑运算符(&&或||)将条件变成一个带有连接的变量,然后运行到if($var)......
<?php
$ar = array(
'index1' => array('bedrooms'=> '1','suburb' => 'one'),
'index2' => array('bedrooms'=>'2', 'suburb'=>'two')
);
$userValBed = '1';
$userSuburb = 'one';
$c = '';
$c .= '($value["'.'bedrooms'.'"] == "'.$userValBed.'") && ';
$c .= '($value["'.'suburb'.'"] == "'.$userSuburb.'")';
foreach($ar as $key => $value){
if($c): // here occurs problem, please fix this.
// if($value["bedrooms"] == "1" && $value["suburb"] == "one"): // comment this line, and uncommet above 'if'.
echo "<br>";
echo "this condtions matches to ";
echo $key . ' key '. '<br>';
endif;
}
?>