Hint = 0. why? if (hint = 0)

Source: Internet
Author: User
The if (hint0) code for hint0 is defined as follows:
 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;?>


In this code:
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 . ""; }


Question 1: I have not defined $ hint = 0. why do I need if ($ hint = "")?
Question 2: for example, if $ hint is not 0, what is the code to be executed?


Reply to discussion (solution)

Where $ hint = 0?

The declaration $ hini = "" is used for storage. $ hini has no value during the first loop, but it will be available during the second loop.

Where $ hint = 0?

$ Hint = ""
Yes, it's not 0, but for convenience I say it's 0

$ Hint = ""; is defined outside of the for loop. when $ I = 0, $ hint is a null string and enters if ($ hint = "") the $ hint is no longer a null string when the judge is in progress but when the loop is added with 1, that is, when $ I = 1. this judgment is to distinguish the first loop.

$ Hint = ""; is defined outside of the for loop. when $ I = 0, $ hint is a null string and enters if ($ hint = "") the $ hint is no longer a null string when the judge is in progress but when the loop is added with 1, that is, when $ I = 1. this judgment is to distinguish the first loop.
Actually, you don't have to judge.

This is used to determine whether it is the first line. if it is not the first line, add
Line Feed
In fact, it is better to give a line feed to CSS without adding
, Which saves you the trouble of making such judgments.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.