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

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

WBOY
Release: 2016-06-13 12:17:23
Original
1433 people have browsed it

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

本帖最后由 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
想想为什么
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template