1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Clarify pitfalls document.

This commit is contained in:
epriestley 2011-06-27 17:40:34 -07:00
parent e24f8b31ad
commit 63436ad74a

View file

@ -4,9 +4,9 @@
This document discusses difficult traps and pitfalls in PHP, and how to avoid, This document discusses difficult traps and pitfalls in PHP, and how to avoid,
work around, or at least understand them. work around, or at least understand them.
= array_merge() in Incredibly Slow = = array_merge() in Incredibly Slow When Merging A List of Arrays =
If you merge arrays like this: If you merge a list of arrays like this:
COUNTEREXAMPLE COUNTEREXAMPLE
$result = array(); $result = array();
@ -14,9 +14,9 @@ If you merge arrays like this:
$result = array_merge($result, $one_list); $result = array_merge($result, $one_list);
} }
...your program now has a huge runtime runtime because it generates a large ...your program now has a huge runtime because it generates a large number of
number of intermediate arrays and copies every element it has previously seen intermediate arrays and copies every element it has previously seen each time
each time you iterate. you iterate.
In a libphutil environment, you can use ##array_mergev($list_of_lists)## In a libphutil environment, you can use ##array_mergev($list_of_lists)##
instead. instead.