title: PHP: Undefined index! But it's defined
body: <p>I'm using Laravel but that shouldn't play a role in this problem:</p>
  
  <p>I'm getting error: </p>
  
  <blockquote>
    <p>Undefined index: AutoID</p>
  </blockquote>
  
  <p>in this:</p>
  
  <pre><code>dump($row); // outputting assoc array on screen
  $id = $row['AutoID']; // getting error here
  </code></pre>
  
  <p>This is how output of array looks like:</p>
  
  <pre><code>array:8 [▼
    "AutoID" =&gt; "6"
    "Numurs" =&gt; "XXXX"
    "Auto" =&gt; "Opel Astra"
    "IzlaidumaGads" =&gt; "2007"
    "BakasTilpums" =&gt; "52.00"
    "KontaktiID" =&gt; "41"
    "Piezimes" =&gt; "NULL"
    "Slegts" =&gt; "1"
  ]
  </code></pre>
  
  <p>As you can see - array starts with index "AutoID".
  Has anyone any clue why this could be happening?</p>
  
  <p>Code is cut out of foreach loop, but 2 lines are really following each other and $row isn't modified anywhere in code. </p>
  
  <p>Also if I try using for example $row['Auto'] - there is no error</p>
  
  <p>Full code: </p>
  
  <pre><code>private function storeCars($arrAuto) {
      $idAssoc = [];
      foreach ($arrAuto as $row) {
          $car = new Car;
  
          $car-&gt;title = $row['Auto'];
          $car-&gt;plate_number = $row['Numurs'];
          $car-&gt;year = (int)$row['IzlaidumaGads'];
          $car-&gt;odometer = 0;
          $car-&gt;tank_size = (float)$row['BakasTilpums'];
          $car-&gt;user_id = (int)$row['KontaktiID'];
          $car-&gt;deleted_at = $row['Slegts'] === '1' ? \Carbon\Carbon::now()-&gt;toDateTimeString() : null;
          $car-&gt;fuel_usage = 0;
  
          $car-&gt;save();
  
          dump($row);
          $id = $row['AutoID'];
          $idAssoc[$id] = $car-&gt;id;
      }
  
      return $idAssoc;
  }
  </code></pre>
  
  <p>dump of full array $arrAuto: <a href="https://pastebin.com/embed_js/taLjWgVy" rel="nofollow noreferrer">https://pastebin.com/embed_js/taLjWgVy</a></p>
  
  <p>I manually hide "Numurs" because that's plate number of actual cars</p>
  
  <p><strong>Sollution:</strong></p>
  
  <p>As you can see by accepted answer: I had some messed up character and index actually was like: "[?]AutoID".</p>
  
  <p>I solved this simply by collecting only values from my array and using n-th value that was stored under "[?]AutoID"</p>