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
Post a Comment