已经定义hint=0为啥还要if(hint=0)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了已经定义hint=0为啥还要if(hint=0),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2142字,纯文字阅读大概需要4分钟。
内容图文
代码如下:load("links.xml");$x=$xmlDoc->getElementsByTagName('link');//get the q parameter from URL$q=$_GET["q"];//lookup all links from the xml file if length of q>0if (strlen($q) > 0){$hint="";for($i=0; $i<($x->length); $i++) { $y=$x->item($i)->getElementsByTagName('title'); $z=$x->item($i)->getElementsByTagName('url'); if ($y->item(0)->nodeType==1) { //find a link matching the search text if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) { if ($hint=="") { $hint="item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . ""; } else { $hint=$hint . "
item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . ""; } } } }}// Set output to "no suggestion" if no hint were found// or to the correct valuesif ($hint == "") { $response="no suggestion"; }else { $response=$hint; } //output the responseecho $response;?>
这段代码中:
if ($hint=="") { $hint="item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . ""; } else { $hint=$hint . "
item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . ""; }
问题1:之前不是已经定义$hint=0了,为啥还要if ($hint=="")?
问题2:如题$hint不=0,后面的代码在执行什么?
回复讨论(解决方案)
where $hint=0 ?
声明$hini=“” 是为了存储用的,第一次循环的时候$hini是没有值的,但是第二次循环的时候就有了啊
where $hint=0 ?
$hint=""
是 ,不是0,但是为了方便我说成是0了
$hint="";是在for循环之外定义的;在$i = 0的时候$hint是空的字符串会进入到if ($hint=="")判断中 但循环加1时也就是$i = 1时此时的$hint已经不再是空的字符串;这个判断就是为了区别第一次循环
$hint="";是在for循环之外定义的;在$i = 0的时候$hint是空的字符串会进入到if ($hint=="")判断中 但循环加1时也就是$i = 1时此时的$hint已经不再是空的字符串;这个判断就是为了区别第一次循环
其实可以不用判断的
这是用来判断是不是第一行,不是第一行的话前面加
换行
其实列表换行这种事,交给CSS来做比较好,不用加
,也就省去这样判断了。
内容总结
以上是互联网集市为您收集整理的已经定义hint=0为啥还要if(hint=0)全部内容,希望文章能够帮你解决已经定义hint=0为啥还要if(hint=0)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。