0
나는 다음과 같은 코드가있다 : 나는이 기능을 사용하려고 시도하고 이제배열 자체 내에서 글로벌 배열을 사용하는 기능을 사용
/**
* Return a configuration setting from the array.
* @example
* GET: conf('url.site') => $conf['url']['site'] = 'localhost'
* SET: conf('url.site', '127.0.0.1') => $conf['url']['site'] = '127.0.0.1'
*
* @param string $path the dot syntax path to resolve into the array
* @param mixed $value the value of the setting that should be set
* @return mixed the value of the setting returned
*/
function conf($path, $value = null) {
global $conf;
$config = $conf;
if($value)
$config = &$conf;
foreach (explode('.', $path) as $key) {
if($value) {
$config = &$config[$key];
continue;
}
$config = $config[$key];
}
if($value)
$config = $value;
return $config;
}
:
$conf = array(
'site' => array(
'theme' => 'master',
),
'url' => array(
'site' => 'localhost',
'up' => conf('url.site') . '/uploads',
'admin' => conf('url.site') . '/admin',
'theme' => conf('url.site') . '/theme/' . conf('site.theme'),
)
);
다음과 같은 기능을 함수에 정의 된 전역 배열 자체에 있습니다.
위에서 볼 수 있듯이,하지만 난 다음 코드를 사용하는 경우 :
echo conf('url.up');
는
/uploads
하지
localhost/uploads
기능은 잘 작동 반환합니다. 하지만 배열 내부에서 올바르게 사용하는 방법을 찾으려고합니다.
반복을 줄이려고합니다. – Xees
당신이하려고하는 것은 PHP가 'url.up'에 접근 할 때 PHP가 그 함수를 호출하도록하는 것이라고 생각합니다. http://stackoverflow.com/questions/1499862/can-you-store-a-function-in-a-php-array가 관련성이 있습니다. –