是否有可能在具有相同数组的另一个元素中引用数组的元素?
假设我们想要制作一个这样的数组:
$a = array(
'base_url' => 'https://rh.example.com',
'URL_SLO_OpenAM_OIC' => 'https://openam.example.com/openam/UI/Logout?goto='.$this['base_url'],
);
Run Code Online (Sandbox Code Playgroud)
当然,它不起作用,因为$this它适用于不适用于数组的类.那还有另一种选择吗?
不,不可能那样.您无法在其上下文中引用相同的数组.但这是一个解决方法:
$a = array(
'base_url' => ($base_url = 'https://rh.example.com'),
'URL_SLO_OpenAM_OIC' => 'https://openam.example.com/openam/UI/Logout?goto='.$base_url,
);
Run Code Online (Sandbox Code Playgroud)