title: Populate multidimensional array with data
body: <p>While renown scientists are looking into other dimensions I'm trying to figure out how to populate multidimensional arrays with dynamic data.</p>
  
  <p>I need to add an undetermined number of values that are calculated from a random function.</p>
  
  <pre><code>function my_random ($min, $max) {
  
          $random_var = rand($min, $max);
          return $random_var;
      }
  </code></pre>
  
  <p>I would like my array to look like this:</p>
  
  <pre><code>$array_example = [
                  'id' =&gt; $id, 
                  'value1' =&gt; $value1,
                  'value2' =&gt; $value2
  
              ];
  </code></pre>
  
  <p>...or maybe like this:</p>
  
  <pre><code>$array[$i] = [
                  'id' =&gt; $id, array(
                      'value1' =&gt; $value1,
                      'value2' =&gt; $value2
                  )   
          ];
  </code></pre>
  
  <p>I figured a simple for-loop would do the trick and so I tried this:</p>
  
  <pre><code>for ($i = 1; $i &lt;= $amount; $i++) {
  
      $array[$i] = $i;
      $array[$i] = [
              'id' =&gt; $i, array(
                  'value1' =&gt; $value1,
                  'value2' =&gt; $value2
              )
          ];
  }
  </code></pre>
  
  <p>...but it comes out all wrong (from console):</p>
  
  <p><code>string(103) "{"id":2,"value1":[14,{"1":{"id":1,"0":{"value1":[14],"value2":[11]}}},13],"value2":[11,19]}"</code></p>
  
  <p>The for-loop seems to nest them. I tried different functions, hoping to get it right: range() to get the id and then populate it with data, array_push() and I even tried to combine and merge.</p>
  
  <p>This <a href="https://stackoverflow.com/questions/3325009/add-data-dynamically-to-an-array">thread</a> makes it look simple: </p>
  
  <pre><code>$array[] = "item";
  $array[$key] = "item";
  array_push($array, "item", "another item");
  </code></pre>
  
  <p>But this solution will only work to create the index.</p>
  
  <p>How do I insert those values into each index dynamically? What I ultimately need is to be able to access the array and its values like this:</p>
  
  <pre><code>$array[0]["value1"].
  </code></pre>
  
  <p>Thanks.</p>