title: How to add an array value to the middle of an associative array?
body: <p>Lets say I have this array:</p>
  
  <p><code>$array = array('a'=&gt;1,'z'=&gt;2,'d'=&gt;4);</code></p>
  
  <p>Later in the script, I want to add the value <code>'c'=&gt;3</code> before <code>'z'</code>. How can I do this?</p>
  
  <p>Yes, the order is important. When I run a foreach() through the array, I do NOT want this newly added value added to the end of the array. I am getting this array from a mysql_fetch_assoc()</p>
  
  <p>The keys I used above are placeholders. Using ksort() will not achieve what I want.</p>
  
  <p><a href="http://www.php.net/manual/en/function.array-splice.php#88896" rel="noreferrer">http://www.php.net/manual/en/function.array-splice.php#88896</a> accomplishes what I'm looking for but I'm looking for something simpler.</p>
  
  <p>Take a sample db table with about 30 columns. I get this data using mysql_fetch_assoc(). In this new array, after column 'pizza' and 'drink', I want to add a new column 'full_dinner' that combines the values of 'pizza' and 'drink' so that when I run a foreach() on the said array, 'full_dinner' comes directly after 'drink'</p>