Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 35 bytes)
<p>I am trying to insert some serial numbers into a database.  I have defined the range for this and I made a function that returns the last record and increments it if I have already inserted the related serial number.  However, I'm getting an error in the code when I attempt to increment the result.  It works fine if I hardcode it but not when I attempt to increment the value:</p>

<pre><code>$batch = $_POST['batch'];
$serial=11111111;
if(array_key_exists('batch',$_POST)){
    $query="select serial from serials where serial like";
    $query.="'".$_POST['batch']."%'";
    $query.='order by serial DESC limit 0,1';
    $rs=mysql_query($query);
    while($row= mysql_fetch_assoc($rs)){
        $a =($row[serial]);
        $a = substr($a,0,2);// substring to match the string
        if($a == $batch){
        $a2 =($row[serial]);
        $a2 = substr($a2,2,-1);//substring to get the serial
        $serial =$a2;
        }
        else
        {
        $serial=11111111;
        };
    }
}
function createColumnsArray($end_column, $first_letters = ''){
    $columns = array();
    $length = strlen($v);
    $letters = range($serial,11111999); //(12847017, 12847027);
    foreach ($letters as $letter){
        $column = $first_letters.$_POST['batch'].$letter.'Z';
        $columns[].=$column;
        if ($column == $end_column)
        return $columns;
    }
    foreach ($columns as $column){
        if (!in_array($end_column, $columns) &amp;&amp; strlen($column) &lt; $length) {
        $new_columns = createColumnsArray($end_column, $column);
        // Merge the new columns which were created with the final columns array.
        $columns = array_merge($columns, $new_columns);
        }
    }
return $columns;
}
</code></pre>
