[数组]请问错出在哪里了
本帖最后由 burner 于 2015-04-01 13:51:31 编辑
<?php<br />$rc = array("07-12"=>"同学聚会", "07-21"=>"信用还贷", "07-23"=>"购买商品");<br />$date = "07-23";<br />foreach($rc as $key=>$value){<br />if($key == $date){<br />echo "<script>alert('".$key."日备忘:".$value."')</script>";<br />break;<br />}else{<br />echo "<script>alert('无备忘')</script>";<br />break;<br />}<br />}<br />?>
Copy after login
第三行如果是:$date = "07-12", 弹出提示框:07-12日备忘:同学聚会
第三行如果是:$date = "07-21",或者是: $date = "07-23",应该同上类似,但是弹出提示框:无备忘
请问错出在哪里了?
------解决思路----------------------$rc = array("07-12"=>"同学聚会", "07-21"=>"信用还贷", "07-23"=>"购买商品");<br />$date = "07-23";<br />$msg = '';<br />foreach($rc as $key=>$value){<br /> if($key == $date){<br /> $msg = "<script>alert('".$key."日备忘:".$value."')</script>";<br /> break;<br /> }<br />}<br />if(! $msg) $msg = "<script>alert('无备忘')</script>";<br />echo $msg;<br />
Copy after login
想想为什么