Undefined offset, CCK field I've been getting the following php notice: 

Notice: Undefined offset: 9 in include() (line 89 of node--name.tpl.php).

Here's the code:

&lt;?php
// loops through array to print out addendum pdf's.
for ($i = 0; $i &lt; 10; $i++) {
  $variable2 = "../sites/default/files/" . $node-&gt;field_addendum['und'][$i]['filename'];
  $variable1 = $node-&gt;field_addendum['und'][$i]['filename'];
  if (isset($variable1)) {
    $result = $i + 1;
    echo "&lt;a href='$variable2' target='_blank'&gt;$result&amp;nbsp&amp;nbsp&amp;nbsp&lt;/a&gt;";}
  else {}
}
?&gt;


The field_addendum is a "file" field type from a custom content type. I understand why I'm getting the notice: if the node only has 3 addendums, once the loop gets to $node->field_addendum['und'][3]['filename'] and onwards, there is nothing in the array.  

Is there a way to get the number of files without having to loop through the array first?
You can try to check if array element exist before assigment, and only if so, assign it, an this way avoid undefined offset:

  if (isset($node-&gt;field_addendum['und'][$i]['filename'])) {
     $variable1 = $node-&gt;field_addendum['und'][$i]['filename'];
    }