PHP array error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anglina
Forum Newbie
Posts: 3
Joined: Mon Dec 28, 2009 8:57 pm

PHP array error

Post 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
Last edited by anglina on Mon Dec 28, 2009 10:12 pm, edited 2 times in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP array error

Post by requinix »

So tell me: at what point is $count greater than 10?
anglina
Forum Newbie
Posts: 3
Joined: Mon Dec 28, 2009 8:57 pm

Re: PHP array error

Post 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?
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: PHP array error

Post 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'];
    }
?>
 
Post Reply