PHP array taking up to much memory
- by Dylan Taylor
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