Passing an array vs Array_merge

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
TipPro
Forum Commoner
Posts: 35
Joined: Wed Mar 15, 2006 6:39 pm

Passing an array vs Array_merge

Post 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;
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply