PHP Variable aliases (References?) - trying to reduce memory usage -


i read answer question led more questions: php variables reference , memory usage

in short, have project i'm trying loop through multidimensional array grab 1 value before continuing on either process or loop. it'll easier explain in code:

// demo variables $this->content['alias1'] = ('object' => new someobject; 'info' => array('type' => 'abc')); $this->content['alias2'] = ('object' => new someobject; 'info' => array('type' => 'def')); $this->content['alias3'] = ('object' => new someobject; 'info' => array('type' => 'abc')); 

... that's incredibly simplified, gets point across. want loop through , find of 'types' 'abc' - what's easiest way it? had this

foreach($this->content $alias => $data) {     if ($data['info'] != 'abc') {        break;     }      // actual "abc" things } 

but i'm trying write of code memory-conscientious can. feel though there's more efficient way this.

i thinking when objects loaded (this config file), assign reference variable, like

$this->types->$type =& $this->content['alias1']; 

for each. in question referenced above, said php uses copy-on-write references - if reference read, never written, efficient way able access object? thinking maybe store array key name in $this->types->$type array.

copy-on-write means php automatically create reference you, provided don't write target variable. if write, copy original value, , modify copy instead. bottom line is: don't need manually assign reference in case, can use regular assignment:

$this->types->$type = $this->content['alias1']; 

as long you're reading $this->types->$type, pointing same value in memory $this->content['alias1'].


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -