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

share|improve this question

76% accept rate
1  
error i think you getting can be easily understand its looks like you are getting the syntax error – NullPointer Oct 27 at 19:09
I would recommend you to use an IDE to code, because it would automatically highlight your syntax errors :) – Kishor Oct 27 at 20:32
@Kishor - Which one do you suggest for Mac? – Raj Oct 29 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. – Kishor Oct 30 at 3:40
feedback

closed as too localized by Jason McCreary, Michael Berkowski, PeeHaa, tereško, Jocelyn Oct 28 at 0:20

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

up vote 3 down vote accepted

You forgot a ) character

if (array_key_exists($searchHobby, $hobbyPeople))
share|improve this answer
Oh shit! so dumb of myself! – Raj Oct 27 at 19:07
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.