note 96219 modified in book.array by thiago

From: Date: Tue, 16 Feb 2010 00:45:47 +0000
Subject: note 96219 modified in book.array by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165989@lists.php.net to get a copy of this message
Be careful when adding elements to a numeric array. I wanted to store some info about some items from a database and decided to use the record id as a key. <?php $key=3000000000; $DATA[$key]=true; ?> This will create an array of 30 million elements and chances are, you will use up all memory with these 2 lines <?php $key=3000000000; $DATA["$key"]=true; ?> This on the other hand will force the array to be an associative array and will only create the one element --was-- Be careful when adding elements to a numeric array. I wanted to store some info about some items from a database and decided to use the record id as a key. $key=3000000000; $DATA[$key]=true; This will create an array of 30 million elements and chances are, you will use up all memory with these 2 lines $key=3000000000; $DATA["$key"]=true; This on the other hand will force the array to be an associative array and will only create the one element http://php.net/manual/en/book.array.php

« previous php.notes (#165989) next »