php - converting config ini like string dot separated value to actual array keys -


got multidimensional array , string in config , need transform array key without use of eval. real world use of problems got big document mongodb transformed multi dimensional array. need define specific array nodes config file.

the idea create config file representation of array key's hierarchy

on config.ini values below example.

colorattribute = attribute.color wholesaleprice = prices.wholesale 

example response mongodb

<?php $products = array(                 'product_name' => 'itouch',                 'brand_name' => 'apple',                 'attributes' => array ( 'color' => 'black',                                         'size' => '5 in'                                       ),                 'prices' => array(                                     'wholesale' => 135,                                     'retail' => 200,                                 ),                 ); 

 function recursekeys(array $keys,array $array){     $key = array_shift($keys);     if(!isset($array[$key])) return null;     return empty($keys) ?       $array[$key]:       recursekeys($keys,$array[$key];  }   var_dump(recursekeys(explode('.',$testconfig),$products); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -