hi everyone,
can anyone tell me why am i getting two outputs when i am only asking for one, well here is the code it will be more self explanatory.
it is simply a dictionary
<?php
// Fill up array with names
$a[]="Hello-common greeting";
$a[]="phone-a comunication device ";
$a[]="pc-personal computer";
$a[]="plane-flying object created to tarnsport objects through air";
$a[]="abba-60's music girls band";
$a[]="brother-close releative";
$a[]="car-transporting device";
$a[]="doctor-person that helps people when they are ill";
$a[]="elephant-huge animal";
$a[]="a-is the first letter in the alphabet";
$a[]="kite-fling object controled by a person on the ground";
$a[]="police-protects people from crimes and danger";
$a[]="pocket-a small holding space atached to the close";
$a[]="abc123-a famous michael jackson song";
//get the q parameter from URL
$q=$_GET["q"];
//lookup all hints from array if length of q>0
if (strlen($q) > 0)
{
$def="";
for($i=0; $i<count($a); $i++)
{//if what i enter is eaqual to one of the elements in the array
if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
{
if ($def=="")
{//value of array is placed in the def variable
$def=$a[$i];
}
else
{//else it is placed below def variable
$def=$def."<br>".$a[$i];
}
}
}
}
echo $q;
echo ("<br>");
if ($def == "")
{
echo("Definition not found");
}
else
{//split the string where "-" and placed in two different variables
list($word, $definition)= split('[-]',$def);
echo $definition;//should only return definition for all possible words
}
?>
well for example if i type in "po" it should give me all possible definitions such as police and pocket but instead it gives me definition for police and just word pocket where it shouldn't even return "word" it should only return definition.
thanks for your help