-1

Am a newbie at PHP. I bet I am doing something silly here and hence am getting the parse error on the line where am invoking array_key_exists() function. But since am a novice at php and since the error thrown by interpreter is so abstract, I cannot make out my mistake. Please see this piece of code and help me:

/* Adding elements into array using [] notations (numbered index) */
$hobbies[] = 'Guitar';
$hobbies[] = 'Reading';
$hobbies[] = 'Singing';
$hobbies[] = 'Travelling';
$hobbyPeople = array(   $hobbies[0] => $names[1],
            $hobbies[1] => $names[3],
            $hobbies[2] => $nickname['shivaraj'],
            $hobbies[3] => $nickname['guru']);
if ($_POST['hobbyName'])
{
    $searchHobby = $_POST['hobbyName'];
    if (array_key_exists($searchHobby, $hobbyPeople)
        print "Yes we have people with hobby you are searching for! And that is: $hobbyPeople[$searchHobby]";
    else
        print "Sorry, we don't have guys with hobby you are searching for!";
}
else
{
print <<<_hobbyTest_
<form method=POST action="$_SERVER[PHP_SELF]">
Enter a hobby you are searching for: <input type="text" name="hobbyName">
<input type="submit" value="Search">
</form>
_hobbyTest_;
}

Thanks, Raj

4
  • 1
    error i think you getting can be easily understand its looks like you are getting the syntax error Commented Oct 27, 2012 at 19:09
  • I would recommend you to use an IDE to code, because it would automatically highlight your syntax errors :) Commented Oct 27, 2012 at 20:32
  • @Kishor - Which one do you suggest for Mac? Commented Oct 29, 2012 at 10:07
  • @Raj - I use PHPDesigner which is pretty good. Checkout if there is a mac version, or any IDE that works on MAC is good to go. Commented Oct 30, 2012 at 3:40

1 Answer 1

3

You forgot a ) character

if (array_key_exists($searchHobby, $hobbyPeople))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.