Associative array with 2 names that are the same?
<p>I'm working on a PHP script that updates some tracking numbers based on an uploaded CSV file. The import worked fine for some time, then the exports started having quotation marks around the values. I thought this would be fine, but it started rejecting the files. Doing some debugging and var_dumps, I discovered a very strange situation I have never seen before - An associative array with two indices <em>with the same name</em>. I ran the code setting the fields (shown below) and added a line:</p>

<pre><code>$v['order_id'] = '119205';
</code></pre>

<p>After running that line, the var_dump was as follows:</p>

<pre><code>array(15) {
  ["order_id"]=&gt;
  string(6) "119205"
  ["Tracking Number"]=&gt;
  string(22) "6735675476254654756"
  ["Postage"]=&gt;
  string(4) "1.64"
  ["order_id"]=&gt;
  string(6) "119205"
}
</code></pre>

<p>Some fields removed for brevity. As you can see, there are two <code>["order_id"]</code> indices. How is this even possible?</p>

<p>Here is the code that sets the values of the array dumped above:</p>

<pre><code>$v = array();
    foreach ($map as $k =&gt; $n) {
    $v[$n] = @$data[$k];
}
</code></pre>

<p>with <code>$map</code> being the CSV header row. Trying to reference <code>$v['order_id']</code> without running the <code>$v['order_id'] = '119205';</code> line resulted in this error:</p>

<pre><code>Notice:  Undefined index: order_id in /dir/to/php/file/php_file.php&lt;/b&gt; on line 29
</code></pre>

<p>Manually setting the index worked as expected, pulling the rest of the data from <code>$v</code> without issue.</p>

<p><strong>EDIT:</strong></p>

<p>Dumping the array_keys resulted in:</p>

<pre><code>[0]=&gt;
string(11) "order_id"
</code></pre>

<p>and:</p>

<pre><code>[14]=&gt;
string(8) "order_id"
</code></pre>

<p>making the first one <em>three characters</em> longer.</p>

<p>var_export still resulted in identical indices.</p>

<p>How can I get rid of these invisible characters? I've already tried <code>$v[trim($n)] = @$data[$k];</code> in the <code>foreach()</code>.</p>
