php extract sub array with specific key -


if have following array:

array(    'var1' => 123,    'var2' => 234,    'var3' => 345 ); 

i extract specific parts of build new array i.e. var1 , var3.

the result looking is:

array(    'var1' => 123,    'var3' => 345 ); 

the example posted stripped down, in reality array has larger number of keys , looking extract larger number of key , keys may or may not present.

is there built in php function this?

edit:

the keys extracted hardcoded array in class i..e $this->keystoextract

$result = array_intersect_key($yourarray,array_flip(array('var1','var3'))); 

so, edit:

$result = array_intersect_key($yourarray,array_flip($this->keystoextract)); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -