PHP array taking up to much memory

Posted by Dylan Taylor on Stack Overflow See other posts from Stack Overflow or by Dylan Taylor
Published on 2010-06-16T03:08:55Z Indexed on 2010/06/16 3:12 UTC
Read the original article Hit count: 385

I have a multidimensional array. The array itself is fine. My problem is that the script takes up monster amounts of memory, and since I'm running this on my MAMP install on my iBook G4, my computer freezes up. Below is the full script.

$query = "SELECT * FROM posts ORDER BY id DESC LIMIT 10"; 
$result = mysql_query($query);
$posts = array();
while($row = mysql_fetch_array($result)){

            $posts[$row["id"]]['post_id'] = $row["id"];
            $posts[$row["id"]]['post_title'] = $row["title"];
            $posts[$row["id"]]['post_text'] = $row["text"];
            $posts[$row["id"]]['post_tags'] = $row["tags"];
            $posts[$row["id"]]['post_category'] = $row["category"];

foreach ($posts as $post) {
   echo $post["post_id"];
}

Is there a workaround that still achieves my goal (to export the MySQL query rows to an array)?

-Dylan

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays