Home >Backend Development >PHP Tutorial >[数组]请教错出在哪里了

[数组]请教错出在哪里了

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:17:231447browse

[数组]请问错出在哪里了

本帖最后由 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 />?>

 
 第三行如果是:$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 />
想想为什么
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn