title: How to create an empty array in PHP with predefined size?
body: <p>I am creating a new array in a for loop.</p>
  
  <pre><code>for $i &lt; $number_of_items
      $data[$i] = $some_data;
  </code></pre>
  
  <p>PHP keeps complaining about the offset since for each iteration I add a new index for the array, which is kind of stupid. </p>
  
  <pre class="lang-none prettyprint-override"><code>Notice: Undefined offset: 1 in include() (line 23 of /...
  Notice: Undefined offset: 1 in include() (line 23 of /..
  Notice: Undefined offset: 1 in include() (line 23 of /..
  </code></pre>
  
  <hr>
  
  <p>Is there some way to predefine the number items in the array so that PHP will not show this notice?</p>
  
  <p>In other words, can I predefine the size of the array in a similar way to this?</p>
  
  <pre><code>$myarray = array($size_of_the_earray);
  </code></pre>