|
Posted by Chung Leong on 07/17/06 17:06
Markus Ernst wrote:
> As Arrays are passed by value and not by reference, you can define the
> new array outside the for loop.
>
> $myArray = array();
> $newArray = array(0, 0, 0);
> for ($i=0; $i<10000; $i++) {
> $myArray[] = $newArray;
> }
>
> or
>
> $myArray = array();
> for ($i=0; $i<10000; $i++) {
> $myArray[] = array(0, 0, 0);
> }
>
> I don't know which is faster.
> Anyway this does not explain the undefined offset notice, and it does
> not really answer why one should do this at all :-)
The first one is faster, since a single array is created vs. 10000. It
also uses a whole lot less memory.
[Back to original message]
|