note 114078 added to language.types.array
| From: | note dot php dot lorriman at spamgourmet dot org | Date: | Thu, 09 Jan 2014 15:02:03 +0000 |
| Subject: | note 114078 added to language.types.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198171@lists.php.net to get a copy of this message | ||
There is another kind of array (php>= 5.3.0) produced by
$array = new SplFixedArray(5);
Standard arrays, as documented here, are marvellously flexible and, due to the underlying hashtable,
extremely fast for certain kinds of lookup operation.
Supposing a large string-keyed array
$arr=['string1'=>$data1, 'string2'=>$data2 etc....]
when getting the keyed data with
$data=$arr['string1'];
php does *not* have to search through the array comparing each key string to the given key
('string1') one by one, which could take a long time with a large array. Instead the
hashtable means that php takes the given key string and computes from it the memory location of the
keyed data, and then instantly retrieves the data. Marvellous! And so quick. And no need to know
anything about hashtables as it's all hidden away.
However, there is a lot of overhead in that. It uses lots of memory, as hashtables tend to (also
nearly doubling on a 64bit server), and should be significantly slower for integer keyed arrays than
old-fashioned (non-hashtable) integer-keyed arrays. For that see more on SplFixedArray :
http://uk3.php.net/SplFixedArray
Unlike a standard php (hashtabled) array, if you lookup by integer then the integer itself denotes
the memory location of the data, no hashtable computation on the integer key needed. This is much
quicker. It's also quicker to build the array compared to the complex operations needed for
hashtables. And it uses a lot less memory as there is no hashtable data structure. This is really an
optimisation decision, but in some cases of large integer keyed arrays it may significantly reduce
server memory and increase performance (including the avoiding of expensive memory deallocation of
hashtable arrays at the exiting of the script).
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/language.types.array.php
Edit -- https://master.php.net/note/edit/114078
Del: integrated -- https://master.php.net/note/delete/114078/integrated
Del: useless -- https://master.php.net/note/delete/114078/useless
Del: bad code -- https://master.php.net/note/delete/114078/bad+code
Del: spam -- https://master.php.net/note/delete/114078/spam
Del: non-english -- https://master.php.net/note/delete/114078/non-english
Del: in docs -- https://master.php.net/note/delete/114078/in+docs
Del: other reasons-- https://master.php.net/note/delete/114078
Reject -- https://master.php.net/note/reject/114078
Search -- https://master.php.net/manage/user-notes.php