...

View Full Version : Doesn't Work!



Zeater
11-21-2007, 09:43 PM
Why doesn't the following code work?, I keep getting greeted with the following error message:

Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in C:\Documents and Settings\User\Desktop\Xampp\htdocs\1.php on line 7.


<?php

session_start();

if (array_key_exists($_GET['id'], $array))
{
echo "Already Exists!";
}
else
{
$_SESSION['ids'][] = $_GET['id'];
$array = $_SESSION['ids'];
}

print_r($array);

?>

Fumigator
11-21-2007, 10:20 PM
Oh look, you answered your own question (of why it doesn't work)!


Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in C:\Documents and Settings\User\Desktop\Xampp\htdocs\1.php on line 7.

Zeater
11-21-2007, 10:38 PM
Yes, but I have it declared in the else section of the IF statement.

PappaJohn
11-21-2007, 10:57 PM
But that is after array_key_exists() has already checked for it.

Fumigator
11-22-2007, 03:42 AM
Yes, but I have it declared in the else section of the IF statement.

Are you under the impression that PHP code is parsed from the bottom up? No WONDER you're so confused! :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum