php中 hint,已经定义hint=0为啥还要if(hint=0)

代码如下:

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; $ilength); $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="" . $y->item(0)->childNodes->item(0)->nodeValue . ""; } else { $hint=$hint . "

" . $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;?>

这段代码中:

回复讨论(解决方案)

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来做比较好,不用加

,也就省去这样判断了。

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值