Page 1 of 1

PHP array error

Posted: Mon Dec 28, 2009 9:10 pm
by anglina
I'm getting an error Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 35 bytes) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\wel1.php on line 9 in following code.

Code: Select all

<?php
 
$count = 1;
 
while ($count <= 10 )
{
$vname = 'text'.$count;
 
$jokes[] = array('id' => '$count', 'name' => '$vname' );
 ++$count;
}
 
echo "will output later";
 
?>
 
memory_limit = 128M in php.ini

php version 5.2.11
Apache version 2.2.14

Re: PHP array error

Posted: Mon Dec 28, 2009 9:34 pm
by requinix
So tell me: at what point is $count greater than 10?

Re: PHP array error

Posted: Mon Dec 28, 2009 10:20 pm
by anglina
tasairis wrote:So tell me: at what point is $count greater than 10?
++$count; added. Fetal error is gone but don't know how to print the array?

Re: PHP array error

Posted: Mon Dec 28, 2009 10:54 pm
by pbs
Try this

Code: Select all

 
<?php
    echo "<pre>";
        print_r($jokes);
    echo "</pre>";  
    
    for($i=0;$i<count($jokes);$i++)
    {
        echo "ID: ".$jokes[$i]['id']."  Name: ".$jokes[$i]['name'];
    }
?>