php - text1/text2 to array['text1']['text2']? -
i'm trying make like
function config( $string ){ require 'configuration.php'; return $config[$string]; } but have problem when config has 2d array. like:
$config['features'] = array( 'memcached' => true, 'compress' => true, 'gzip' => true ); how can config('features/memcached') or if can have 3 or more threaded array config('features/memcached/version14/etc') ( example ) return true still works when config('features') returns array function above. ideas ?
just split string keys:
function config( $string ){ require 'configuration.php'; $keys = explode('/',$string); $return = $config; foreach($keys $key){ $return = $return[$key]; } return $return; } here can too:
config('features/others/foo/bar'); if exists:
$config['features'] = array( 'memcached' => true, 'others' => array( 'foo' => array( 'bar' => 42 ) ) );
Comments
Post a Comment