My script works, but it's throwing a PHP Notice:
PHP Notice: Undefined offset: 0 in /Users/petiejoe/site/index.php on line 168

in my log. the number ranges from 0 to 9, and it is on several different lines. Each of the lines has something to the effect of

	list($num, $title, $body, $extended, $background, $category, $date, $rating, $datenum, $numcomments)=$entry;

where $entry is (supposed to be) an array populated by an SQL call, containing the appropriate number of indexes (i.e., it should be something like array(10, "title", "entry","extended", etc...)).

Is this a sign that something else is possibly slightly off, or is it because of the way the list() function works? As I said, the command still works (I can use the variables later in the script), but I would like to know why the log seems to think there is a problem.

Thanks in advance.

    Do a print_r on $entry just before (or after) the call to list and then post the output from it.

    print_r($entry);
    

      edit: below is an output for:

      list($num, $title, $picdir, $descrip, $has_index, $rating, $category, $date, $datenum, $numcomments)=$entry;

      sorry that it's so long... as you can see, it has the 0,1,2,etc... index there. Glitch in list(), or am I missing something?

       before:
      Array
      (
          [0] => 27
          [entry] => 27
          [1] => 18 of 87 pictures
          [title] => 18 of 87 pictures
          [2] => 20040505-5
          [URL] => 20040505-5
          [3] => "blah blah blah (same as below)"
          [4] => 
          [has_index] => 
          [5] => 
          [currentrating] => 
          [6] => 
          [category] => 
          [7] => Wed May 05 2004 at 11:47 PM
          [DATE_FORMAT(date, '%a %M %d %Y at %l:%i %p')] => Wed May 05 2004 at 11:47 PM
          [8] => 20040505234704
          [date] => 20040505234704
          [9] => 1
          [numcomments] => 1
          [10] => 20040505
          [day] => 20040505
      )
      
      after:
      Array
      (
          [0] => 27
          [entry] => 27
          [1] => 18 of 87 pictures
          [title] => 18 of 87 pictures
          [2] => 20040505-5
          [URL] => 20040505-5
          [3] => "What do you take <a href="/RAM/index.php?entry=238">1,000+ pictures</a> of?" she asked. I stopped and thought for  a bit and realized that in reality, I could only count a fraction of those, because many were duplicates of the same subject. For instance, I took over a hundred pictures of Monument Valley, but you wouldn't really want to sit down and look at more than 20-30 of them. I took 50 pictures of two turtles, for crying out loud.<br />
      <br />
      So what *would* one take 1,000 pictures of, I asked myself. I didn't have a camera that could handle taking 1,000 pictures (or at least not enough disks to hold them all), so I set out to take 100 pictures. 100 totally different pictures. Every one with a completely different subject, not related to each other at all. I fell short of the goal, simply because I ran out of disk space. It was bright and sunny, so the file sizes are a bit larger than when it's dark, and I couldn't fit 20 on each disk.<br />
      <br />
      So I didn't make it to 100, but the point is still the same. In half an hour and half a mile, I took 87 pictures. Each picture is of something different, no two are alike. Some aren't very spectacular, one is completely out of focus (whoops), and a couple of them are pretty darn cool shots. None of them are hi-res, because I was using my own camera, but several of them hit the spot I was looking for. It doesn't matter which one is looked at first, nor last. The only determining order is where I happened to be when.<br />
      <br />
      So how could one take 1,000 pictures? Easy... give me 5.75 hours and 5.75 miles, and I could find 1,000 things to take pictures of. For now, here's a half hour and half mile... 87 pictures.
          [description] => "What do you take <a href="/RAM/index.php?entry=238">1,000+ pictures</a> of?" she asked. I stopped and thought for  a bit and realized that in reality, I could only count a fraction of those, because many were duplicates of the same subject. For instance, I took over a hundred pictures of Monument Valley, but you wouldn't really want to sit down and look at more than 20-30 of them. I took 50 pictures of two turtles, for crying out loud.<br />
      <br />
      So what *would* one take 1,000 pictures of, I asked myself. I didn't have a camera that could handle taking 1,000 pictures (or at least not enough disks to hold them all), so I set out to take 100 pictures. 100 totally different pictures. Every one with a completely different subject, not related to each other at all. I fell short of the goal, simply because I ran out of disk space. It was bright and sunny, so the file sizes are a bit larger than when it's dark, and I couldn't fit 20 on each disk.<br />
      <br />
      So I didn't make it to 100, but the point is still the same. In half an hour and half a mile, I took 87 pictures. Each picture is of something different, no two are alike. Some aren't very spectacular, one is completely out of focus (whoops), and a couple of them are pretty darn cool shots. None of them are hi-res, because I was using my own camera, but several of them hit the spot I was looking for. It doesn't matter which one is looked at first, nor last. The only determining order is where I happened to be when.<br />
      <br />
      So how could one take 1,000 pictures? Easy... give me 5.75 hours and 5.75 miles, and I could find 1,000 things to take pictures of. For now, here's a half hour and half mile... 87 pictures.
          [4] => 
          [has_index] => 
          [5] => 
          [currentrating] => 
          [6] => 
          [category] => 
          [7] => Wed May 05 2004 at 11:47 PM
          [DATE_FORMAT(date, '%a %M %d %Y at %l:%i %p')] => Wed May 05 2004 at 11:47 PM
          [8] => 20040505234704
          [date] => 20040505234704
          [9] => 1
          [numcomments] => 1
          [10] => 20040505
          [day] => 20040505
      )

        You have 14 elements in the array but you're only listing 10 in the list() function. It's warning you that you're missing out on 4 variables. If you want to get rid of the warning just add a couple of filler variables on the end, you can set them to null after the call or use refferences if you want to save on memory.

          a year later

          I'm getting the same notice :

          undefined offset: 1 in file myscript.php line 72

          here is line 72:

          list($key,$val) = explode("=", $lines[$i]);

          $lines is an array, which was itself populated from an explode(), in the line:

          $lines = explode("\n", $res);

          Basically, $lines is a bunch of lines of parameter values, in the format 'key=value'

          I did an echo on each element of $lines, and noticed that there is one line that doesn't have a value; it is : 'custom='

          The posts above said something about this notice just warning you that you're missing values, or some kind of mis-match between the list() values and what you're trying to assign to them.

          Could the 'custom=' be what's producing the undefined offset?

            Write a Reply...