title: Undefined index: Array, when the index is defined
body: <p>This is making me crazy, because I need E_ALL turned on for other reasons. I can't get rid of this bug. </p>
  
  <p>Here is my function:</p>
  
  <pre><code>public static function getFileCatsString($categories)
  {
      if (empty($categories)) {
          return '';
      }
      $cats = self::getFileCats();
  
      $file_cats_string = '';
      $categories_array = explode(',',$categories);
      foreach($categories_array as $k=&gt;$category_id) {
          $file_cats_string.=$cats[$category_id].', ';
      }
      $file_cats_string = rtrim($file_cats_string, ', ');
      return($file_cats_string);
  }
  </code></pre>
  
  <p>Categories are stored in keyed array: [id]=>[string]</p>
  
  <p>$categories that gets passed is a string of category_ids (long story as to why that is)</p>
  
  <p>the getFileCats() method gets a list of all available categories.</p>
  
  <p>So we explode the commad list to create an array, and then we loop through that array. I simply want to create, a string of category labels when I'm given a string of category ids. PHP returns this warning:</p>
  
  <blockquote>
    <p>Notice: Undefined index: Array in Documents.php on line 40</p>
  </blockquote>
  
  <p>Line 40 is: </p>
  
  <blockquote>
  <pre><code>      $file_cats_string.=$cats[$category_id].', ';
  </code></pre>
  </blockquote>
  
  <p>So obviously the undefined index is $cats[$category_id]. But here's where it gets weird.</p>
  
  <p>If I use a die() statement and echo out $cats[$category_id] I indeed get a string, not an array.</p>
  
  <p>By the way, here is the output of each of the three key pieces of data with a die() statement put at the top of the foreach loop.</p>
  
  <p>$categories_array:</p>
  
  <blockquote>
    <p>Array ( [0] => 2 )</p>
  </blockquote>
  
  <p>$cats: </p>
  
  <blockquote>
    <p>Array ( [9] => Category 19 [8] => Category 8 [7] => Category 7 [6] => Another String I Changed For Privacy [5] => AED Sales [4] => Preceptor Folder [3] => Education Brochures [2] => Forms [1] => Guidelines and Policies )</p>
  </blockquote>
  
  <p>$cats[$category_id]</p>
  
  <blockquote>
    <p>Forms</p>
  </blockquote>
  
  <p>$category_id</p>
  
  <blockquote>
    <p>2</p>
  </blockquote>
  
  <p>It gets weirder though. It says that the index is an array (which would indeed be a problem), so I tried putting:</p>
  
  <pre><code>        if (is_array($category_id)) {
              die(print_r($categories_array, true) . '&lt;br /&gt;' . print_r($cats, true) . '&lt;br /&gt;' . $cats[$category_id] . '&lt;br /&gt;' . $category_id);
          }
  </code></pre>
  
  <p>to see if I could identify a piece of defending data, but it never dies. So what in the heck is going on?! (I have a sneaky suspicion that the answer is going to be forehead-slappingly simple.)</p>