【发布时间】:2013-11-04 11:33:36
【问题描述】:
我想用逻辑运算符(&& 或 ||)将条件变成一个带有连接的变量,然后运行到 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;
}
?>
【问题讨论】:
-
解析错误:语法错误,D:\xampp\htdocs\search-code.php(128) 中的文件意外结束:第 1 行的 eval() 代码
标签: php if-statement logical-operators