Page 1 of 1

Passing an array vs Array_merge

Posted: Wed Mar 15, 2006 6:54 pm
by TipPro
Does anyone have comments on what technique would be faster, use less memory, etc...

Code: Select all

/************ START - Technique 1 ***********/
function mainProcess(){
        while(something){
                $totalCollection = $this->collectMore($totalCollection);
        }
}
	
function collectMore($passedArray){
        while(something){
                $passedArray[] = $newObject;
          }
          return $passedArray;
}


/************ START - Technique 2 ***********/
function mainProcess(){
        while(something){
                $totalCollection = array_merge($totalCollection, $this->collectMore());
        }
}
	
function collectMore(){
        while(something){
                $passedArray[] = $newObject;
          }
          return $passedArray;
}

Posted: Wed Mar 15, 2006 7:05 pm
by feyd
what's faster is generally build and situation specific, but I'd think array_merge() would, technically be faster, but the first one is more object oriented.