SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What is this error?

    Notice: Undefined index: 27 in /var/www/html/johnsonpublishing.com/webadmin/members/members_list.html on line 456


    This is line 456
    $lists_display[] = $lists_array["$lists_ID"];

    Here is the entire code
    if ($lists != "") {
    $lists_display = Array();
    $lists = explode(",", $lists);
    foreach($lists AS $lists_ID) {
    if ($lists_ID != "") {
    $lists_display[] = $lists_array["$lists_ID"];

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its kinda like an undefined variable notice, except its saying the array element is undefined.

    given the following array
    PHP Code:

    $array 
    = array(
       
    'foo' => 5,
        
    'bar' => 5
    );

    // works, because $array['foo'] exists
    echo $array['foo'];


    // generates undefined index notice
    echo $array['lenora']; 

    using $array['lenora'] gives the undefined index notice, because there is no 'lenora' element in the array to use.


    you can use isset() or array_key_exists() to check if a variable/array element exists. they have slightly different behavior, the php manual explains the difference.

  3. #3
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array reply

    Since it doesn't exist why can't I take it out?

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The error means that on this line
    PHP Code:
    $lists_display[] = $lists_array["$lists_ID"]; 
    $lists_ID is equal to some value that's not in $lists_array.

    Since I can't see the source of the $lists variable that populated $lists_array, I can't tell you where or how you could take out whatever's not being found. As clamcrusher said, you would use array_key_exists() to see if $lists_ID is in $lists_array before assigning it to $lists_display if you want to avoid this notice.

  5. #5
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been working on the file for two days now and its still is not right, may I send you the source file so you can tell me what it is I am doing wrong?


Bookmarks

Posting Permissions

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