PHP Arrays: How to add 'key & value' to an existing array
<p>I do not know how to add a key and value to the existing array. My array goes like this. Initially I have tried adding using <code>array_push()</code> but it added not as I needed it.</p>
<p>I have given my output after I gave the 'var_dump'.</p>
<pre><code>array (size=5)
  0 =&gt; 
    array (size=3)
     'id' =&gt; int 7
      'title' =&gt; string 'Pongal' (length=6)
      'start' =&gt; string '2016-05-16' (length=10)
  1 =&gt; 
    array (size=3)
       'id' =&gt; int 8
      'title' =&gt; string 'big day' (length=7)
      'start' =&gt; string '2016-05-04' (length=10)
  2 =&gt; 
    array (size=3)
      'id' =&gt; int 9
      'title' =&gt; string 'marriage day' (length=12)
      'start' =&gt; string '2016-05-19' (length=10)
  3 =&gt; 
    array (size=3)
      'id' =&gt; int 10
      'title' =&gt; string 'Karthiks  bday' (length=14)
      'start' =&gt; string '2016-06-11' (length=10)
  4 =&gt; 
    array (size=3)
      'id' =&gt; int 12
     'title' =&gt; string 'Election date announced' (length=23)
      'start' =&gt; string '2016-06-01' (length=10)
</code></pre>
<p>Now, I'd like to insert array('sample_key' =&gt; 'sample_value') after all the  elements of each array.</p>
<p>How can I do it? This is I want the result to be like this:-</p>
<pre><code>array (size=5)
  0 =&gt; 
    array (size=4)
      'id' =&gt; int 7
      'title' =&gt; string 'Pongal' (length=6)
      'start' =&gt; string '2016-05-16' (length=10)
      ‘color’ =&gt; ‘red’
  1 =&gt; 
    array (size=4)
      'id' =&gt; int 8
      'title' =&gt; string 'big day' (length=7)
      'start' =&gt; string '2016-05-04' (length=10)
      ‘color’ =&gt; ‘red’
  2 =&gt; 
    array (size=4)
      'id' =&gt; int 9
      'title' =&gt; string 'marriage day' (length=12)
      'start' =&gt; string '2016-05-19' (length=10)
      ‘color’ =&gt; ‘red’
  3 =&gt; 
    array (size=4)
      'id' =&gt; int 10
      'title' =&gt; string 'Karthiks  bday' (length=14)
      'start' =&gt; string '2016-06-11' (length=10)
      ‘color’ =&gt; ‘red’
  4 =&gt; 
    array (size=4)
      'id' =&gt; int 12
      'title' =&gt; string 'Election date announced' (length=23)
      'start' =&gt; string '2016-06-01' (length=10)
      ‘color’ =&gt; ‘red’
</code></pre>
<p><strong>Note that I have added 'color' =&gt; 'red' to all the indexes</strong></p>