Subject: ImageLine Undefined offset error
Posted By: ss2003 Post Date: 1/13/2004 2:27:58 PM
I have a problem with my index. I have two arrays, one for the x coordinates $ld(), and one for the y coordiantes $la(). I want to draw lines betwween my points but I get an error message when ever I put in the $i+1 for the index of the second point.
Here's the code:

1400 for ($i = 0; $i < 1293; $i++) {
1401 ImageLine($im, $ld[$i], $la[$i], $ld[$i+1], $la[$i+1], $white);
1402 }

Here's the error:

<br />
<b>Notice</b>:  Undefined offset:  1293 in <b>C:\Program Files\Abyss Web Server\htdocs\Test7.php</b> on line <b>1401</b><br />
<br />
<b>Notice</b>:  Undefined offset:  1293 in <b>C:\Program Files\Abyss Web Server\htdocs\Test7.php</b> on line <b>1401</b><br />
‰PNG
IHDRXXÃpO    PLTE (blah, blah, blah...)

What am I doing wrong?

Thanks!

Reply By: richard.york Reply Date: 1/13/2004 3:16:34 PM
Well your program is complaining that that array indice doesn't exist.

Undefined offset will mean that a numeric based array indice isn't set at the time of use.

So echo the value of
echo $Id[$i];

Then look elsewhere in your script to be sure that $id[$i+1]; exists.  If these are built using loops, does that loop iterate 1293 times?

If you need to detect whether a variable exists, or whether it contains a value look at isset and empty.

http://www.php.net/isset
http://www.php.net/empty

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::

Reply By: nikolai Reply Date: 1/13/2004 3:22:50 PM
Since you're only seeing the error once, I would guess that you're iterating your loop one too many times.  If your last index is 1292, then the last *starting* point should be at index 1291, since that line's other endpoint is stored in index 1292.

Make sense?


Take care,

Nik
http://www.bigaction.org/
Reply By: ss2003 Reply Date: 1/13/2004 3:37:58 PM
Thanks, that's it exactly!


Go to topic 8505

Return to index page 970
Return to index page 969
Return to index page 968
Return to index page 967
Return to index page 966
Return to index page 965
Return to index page 964
Return to index page 963
Return to index page 962
Return to index page 961