title: Trying to create a grid map in an array returns a fatal memory error in php
body: <p>I am working on a random RPG Map generator that get's inserted into the database for later retrieval. Basically the user will enter some minor details on the form and specify how many tiles of each terrain they need to have on the map. Then the tiles are randomly inserted into the map and database. I insert the tiles into an Array and then shuffle the results. I do a loop through the array and loop through and X &amp; Y grid to insert the terrain data. But everytime I do that, I get a memory error: <strong>Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 32 bytes)</strong> This is my code:</p>
  
  <pre><code>$gridarray = array();
  
  for ($jungle1 = 0; $jungle1 &lt;= $jungle -1; $jungle1++) {
  array_push($gridarray,"jungle");
  }
  
  for ($swamp1 = 0; $swamp1 &lt;= $swamp -1; $swamp1++) {
  array_push($gridarray,"swamp");
  }
  
  for ($cave1 = 0; $cave1 &lt;= $cave -1; $cave1++) {
  array_push($gridarray,"cave");
  }
  
  for ($mountain1 = 0; $mountain1 &lt;= $mountain -1; $mountain1++) {
  array_push($gridarray,"mountain");
  }
  for ($ocean1 = 0; $ocean1 &lt;= $ocean -1; $ocean1++) {
  array_push($gridarray,"ocean");
  }
  
  for ($volcanic1 = 0; $volcanic1 &lt;= $volcanic -1; $volcanic1++) {
  array_push($gridarray,"volcanic");
  }
  
  for ($desert1 = 0; $desert1 &lt;= $desert -1; $desert1++) {
  array_push($gridarray,"desert");
  }
  
  for ($dirt1 = 0; $dirt1 &lt;= $dirt -1; $dirt1++) {
  array_push($gridarray,"dirt");
  }
  
  for ($forest1 = 0; $forest1 &lt;= $forest -1; $forest++) {
  
  array_push($gridarray,"dirt");
  }
  
  for ($arctic1 = 0; $arctic1 &lt;= $arctic -1; $arctic++) {
  
  array_push($gridarray,"arctic");
  }
  
  for ($grass1 = 0; $grass1 &lt;= $grass -1; $grass++) {
  
  array_push($gridarray,"grass");
  }
  
  echo '&lt;table cellspacing="0" cellpadding="0" border="0"&gt;';
  $gridsquare = $xsize * $ysize;
  
  $grid = 0;
  shuffle($gridarray);
  
  
  
  for ($x = 1; $x &lt;= $xsize; $x++) {
      echo '&lt;tr&gt;';
            for ($y = 1; $y &lt;= $ysize; $y++) {
  
             $terrain = $gridarray[$grid];
             $terrain_img = 'http://www.sw-bfs.com/images/grids/' . $terrain . '.png';
  
  $query2 = " INSERT INTO terrain ( ent_id, ent_type, grid_img, grid_type, grid_exit_e, grid_exit_w, grid_exit_s, grid_exit_n, grid_exit_u, grid_exit_d, x, y)  VALUES ( '$loc_id', 'terrain', '$terrain_img', '$terrain','1', '1', '1', '1', '0', '0', '$x', '$y') "; 
  
   $result2 = mysql_query($query2) or die(mysql_error());
  
  echo '&lt;td&gt;&lt;img src="' . $terrain_img . '" title="' . $terrain . '"/&gt;&lt;/td&gt;';
  
  $grid++;
  
  
  
  } 
  echo '&lt;/tr&gt;';
  
  
  } 
  echo "&lt;/table&gt;";
  </code></pre>
  
  <p>It is telling me that the error is occurring on the line that reads like this:</p>
  
  <pre><code>array_push($gridarray,"arctic");
  }
  </code></pre>
  
  <p>Obviously I am doing something wrong or at least I am not writing the code efficiently enough. Forgive me, I am still learning. Can someone provide some better assistance? Thank you in advance.</p>