Home > Backend Development > PHP Tutorial > 为什么这段代码没效果

为什么这段代码没效果

WBOY
Release: 2016-06-06 20:18:27
Original
1507 people have browsed it

<code><?php if ($_GET['cate']==''||$_GET['cate']='diary' ) {
echo '<a class="is" href="?cate=diary">DIARY<a href="?cate=blog">BLOG</a>';
} elseif ($_GET['cate']='blog') {
echo '<a href="?cate=diary">DIARY</a><a class="is" href="?cate=blog">BLOG</a>';
} 
?></code>
Copy after login
Copy after login

不管为cate设置什么值都输出<a class="is" href="?cate=diary">DIARY</a><a href="?cate=blog">BLOG</a>

回复内容:

<code><?php if ($_GET['cate']==''||$_GET['cate']='diary' ) {
echo '<a class="is" href="?cate=diary">DIARY<a href="?cate=blog">BLOG</a>';
} elseif ($_GET['cate']='blog') {
echo '<a href="?cate=diary">DIARY</a><a class="is" href="?cate=blog">BLOG</a>';
} 
?></code>
Copy after login
Copy after login

不管为cate设置什么值都输出<a class="is" href="?cate=diary">DIARY</a><a href="?cate=blog">BLOG</a>

<code class="php"><?php if ($_GET['cate']==''||$_GET['cate']=='diary' ) {
echo '<a class="is" href="?cate=diary">DIARY<a href="?cate=blog">BLOG</a>';
} elseif ($_GET['cate']=='blog') {
echo '<a href="?cate=diary">DIARY</a><a class="is" href="?cate=blog">BLOG</a>';
} 
?></code>
Copy after login

== 符号写错了

$_GET['cate']================='diary'

粗心的小明, if条件第二个表达式永远为真 elseif的条件也是。

粗心的小明死在了==上了

你以后写 逻辑表达式的时候,养成把期望值放在前面的习惯,这样,你不小心把==打成=的时候,就会报错。个人认为编码风格可以参考CI框架的,他的文档上面会有说明

Related labels:
php
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