-1

我是 PHP 的新手。我敢打赌我在这里做了一些愚蠢的事情,因此在调用array_key_exists()函数的行上出现解析错误。但是由于我是 php 的新手,并且由于解释器抛出的错误是如此抽象,所以我无法弄清楚我的错误。请查看这段代码并帮助我:

/* 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_;
}

谢谢,拉吉

4

1 回答 1

3

你忘了一个 ) 字符

if (array_key_exists($searchHobby, $hobbyPeople))
于 2012-10-27T19:06:54.447 回答