title: How to use array_push with associative array and index key?
body: <p>I am a bit 'rusty with php as it happens that sometimes I use it for weeks and sometimes it happens that you do not use for months. Either way I'm trying to pass values of another array are "array", on another array in an orderly manner ... What I want to do is essentially create a key that allows me to organize incremental values per line, in particular;</p>
  
  <p><strong>array content</strong></p>
  
  <pre><code>Array 
  (
      [key] =&gt; value
      [2] =&gt; 1 
      [3] =&gt; Inter 
      [4] =&gt; 4 
      [5] =&gt; 4 
      [6] =&gt; 0 
      [7] =&gt; 0 
      [8] =&gt; 5 
      [9] =&gt; 1
      [10] =&gt; +4
      [11] =&gt; 12
      [12] =&gt; Chievo Verona - Inter 0 - 1
      [13] =&gt; Inter - Milan 1 - 0
      [14] =&gt; Carpi - Inter 1 - 2
      [15] =&gt; Inter - Atalanta 1 - 0
      [16] =&gt; ;
      [17] =&gt; 2
      [18] =&gt; Torino
      [19] =&gt; 4
      [20] =&gt; 3
      [21] =&gt; 1
      [22] =&gt; 0
      [23] =&gt; 9
      [24] =&gt; 4
      [25] =&gt; +5
      [26] =&gt; 10
      [27] =&gt; Torino - Sampdoria 2 - 0
      [28] =&gt; Hellas Verona - Torino 2 - 2
      [29] =&gt; Torino - Fiorentina 3 - 1
      [30] =&gt; Frosinone - Torino 1 - 2
      [31] =&gt; ;
      [32] =&gt; 3
      [33] =&gt; Fiorentina
      [34] =&gt; 4
      [35] =&gt; 3
      [36] =&gt; 0
      [37] =&gt; 1
      [38] =&gt; 5
      [39] =&gt; 3
      [40] =&gt; +2
      [41] =&gt; 9
      [42] =&gt; Carpi - Fiorentina 0 - 1
      [43] =&gt; Fiorentina - Genoa 1 - 0
      [44] =&gt; Torino - Fiorentina 3 - 1
      [45] =&gt; Fiorentina - Milan 2 - 0
      [46] =&gt; ;
      [47] =&gt; 4
      [48] =&gt; Roma
      [49] =&gt; 4
      [50] =&gt; 2 
  </code></pre>
  
  <p>the ";" It'll need to be able to recognize where you break the line, I do not remember if there is any method that allows me to access the next key.</p>
  
  <p>Currently my code is:</p>
  
  <pre><code>$classifica = array("key" =&gt; "value");
  function buildArrayClassifica()
  {
      global $array; 
      global $classifica;
  
      $i = 0; 
  
      foreach(array_slice($array,1)  as $key =&gt; $value) 
      {
          if($value != ";")
          {
              array_push($classifica[$i], $value); //there is a problem
              echo $value . " ";
          }
          else if($value == "value ")
          {
              continue;
          }
          else
          {
              $i++;         
              echo "&lt;br/&gt;";
          }
      }
  }
  </code></pre>
  
  <p>The code I will return this error:</p>
  
  <blockquote>
    <p>Warning: array_push () Expects parameter 1 to be array, null given in...</p>
  </blockquote>
  
  <p>in particular on array_push, it seems not to accept incremental keys or maybe I'm doing it the wrong way.
  Can anyone tell me how to solve?</p>
  
  <p><strong>UPDATING</strong></p>
  
  <p>As you have seen the issue is not simple and it is quite difficult to explain the problem, but I will try to be even clearer to meet.
  As you can see above you are the structure of the array "array", but is a disordered structure that needs to be ordered in an additional array. To recapitulate the structure of the array "array" is:</p>
  
  <pre><code>1 , Inter , 4 , 4 , 0 , 0 , 5 , 1 , +4 , 12 , Chievo Verona - Inter 0 - 1 , Inter - Milan 1 - 0 , Carpi - Inter 1 - 2 , Inter - Atalanta 1 - 0 , ;
  </code></pre>
  
  <p>the ";" means that the line is finished. So the next value near the ";" means that a new line coming. What I need is move all the value of <code>"array"</code> in array <code>classifica</code>, but I want organize them for:</p>
  
  <pre><code>ROW1 =&gt;  1 , Inter , 4 , 4 , 0 , 0 , 5 , 1 , +4 , 12 , Chievo Verona - Inter 0 - 1 , Inter - Milan 1 - 0 , Carpi - Inter 1 - 2 , Inter - Atalanta 1 - 0 
  ROW2 =&gt; Other values...
  </code></pre>
  
  <p>So the ROW1, 2 .. rapresents the key of the array <code>classifica</code>. I'm trying to push the value inside a row and after it increment $i <code>index</code> but the code doesn't add the value because the index replace in loop the actual key, for example:</p>
  
  <pre><code>actual foreach content:
  $i = 0
  value = "Inter"
  content of array=&gt; [0] =&gt; Inter
  now the $i is ever 0 because the row isn't finished yet, the ";" 
  it has not yet been reached, so the next content of foreach is:
  "1" but replace the "Inter" value, so this is a problem.
  </code></pre>