title: Why am I getting Notice: Undefined index: id in php?
body: <p>I've written a PHP function that reads in a file of orders and stores them into an array. When I load my web page, I am getting:</p>
  <pre><code>Notice: Undefined index: id on line 112 
  </code></pre>
  <p>which is the final <code>$orders[$order['id']] = $order;</code></p>
  <p>Here's my function code</p>
  <pre><code>function readOrders($filename)
  {
      $arr = file($filename) or die('ERROR: Cannot find file');
  
      $delimiter = ',';
  
      // reading in customers from file and storing in array of customers
      foreach ($arr as $line) {
  
          $splitcontents = explode($delimiter, $line);
  
          $order = array();
  
          $orders['id'] = $splitcontents[1];
          $orders['isbn'] = $splitcontents[2];
          $orders['title'] = utf8_encode($splitcontents[3]);
          $orders['category'] = utf8_encode($splitcontents[4]);
  
          $orders[$order['id']] = $order;
      }
      return $orders;
  }
  </code></pre>