Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Doesn't Work!

  1. #1
    Banned
    Join Date
    Nov 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Doesn't Work!

    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.

    Code:
    <?php
    
    session_start();
    
    if (array_key_exists($_GET['id'], $array))
    {
      echo "Already Exists!";
    }
    else
    {
      $_SESSION['ids'][] = $_GET['id'];
      $array = $_SESSION['ids'];
    }
    
    print_r($array);
    
    ?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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.

  • #3
    Banned
    Join Date
    Nov 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, but I have it declared in the else section of the IF statement.

  • #4
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    But that is after array_key_exists() has already checked for it.
    John

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •