有谁知道如何使用 FOREACH 循环来获取与标准相关的整个信息块:“大于”用户发布的数字(在本例中为 $metsq=$_POST['metersq'];)
例如,在我发布的代码,如果用户写90,它应该只输出
color - blue
msq - 100
city - Prague
我试过这段代码,但显然我没有太多经验。提前致谢!
<?php
if(isset($_POST['button'])){
$houses = array(
'house1'=>array(
'color'=>'green',
'msq'=>100,
'city'=>'Prague'
),
'house2'=>array(
'color'=>'red',
'msq'=>30,
'city'=>'Belgrade'
),
'house3'=>array(
'color'=>'blue',
'msq'=>50,
'city'=>'London'
),
'house4'=>array(
'color'=>'blue',
'msq'=>50,
'city'=>'Belgrade'
)
);
$col=$_POST['colors'];
$metsq=$_POST['metersq'];
$cit=$_POST['cities'];
foreach($houses as $house=>$data) {
foreach($data as $key=>$value) {
if($value>=$metsq) {
echo "$key - $value </br>";
}
}
} else {
echo "Go, search";
}
?>
<form action="?" method="post">
<select name="colors" >
<option>green</option></br>
<option>blue</option></br>
<option>red</option></br>
</select>
<input type="number" name="metersq" id="metersq" maxlength="3" />m2</br>
<select name="cities">
<option>Prague</option></br>
<option>Belgrade</option></br>
<option>London</option></br>
</select>
<input type="submit" value="Find" name="button"id="button" />